forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Primary Changes --------------- 1. Create a test tooling class for DAML AIO Image Fixes hyperledger-cacti#3435 Signed-off-by: raynato.c.pedrajeta <[email protected]>
- Loading branch information
1 parent
ec9683d
commit 0d4770b
Showing
8 changed files
with
735 additions
and
3 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
packages/cactus-plugin-ledger-connector-daml/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
"name": "@hyperledger/cactus-plugin-ledger-connector-daml", | ||
"version": "2.0.0-rc.3", | ||
"description": "Allows Cactus nodes to connect to a DAML ledger.", | ||
"keywords": [ | ||
"Hyperledger", | ||
"Cactus", | ||
"Integration", | ||
"Blockchain", | ||
"Distributed Ledger Technology" | ||
], | ||
"homepage": "https://github.com/hyperledger/cacti#readme", | ||
"bugs": { | ||
"url": "https://github.com/hyperledger/cacti/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/hyperledger/cacti.git" | ||
}, | ||
"license": "Apache-2.0", | ||
"author": { | ||
"name": "Hyperledger Cactus Contributors", | ||
"email": "[email protected]", | ||
"url": "https://www.hyperledger.org/use/cacti" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Please add yourself to the list of contributors", | ||
"email": "[email protected]", | ||
"url": "https://example.com" | ||
}, | ||
{ | ||
"name": "Peter Somogyvari", | ||
"email": "[email protected]", | ||
"url": "https://accenture.com" | ||
} | ||
], | ||
"main": "dist/lib/main/typescript/index.js", | ||
"module": "dist/lib/main/typescript/index.js", | ||
"browser": "dist/cactus-plugin-ledger-connector-corda.web.umd.js", | ||
"types": "dist/lib/main/typescript/index.d.ts", | ||
"files": [ | ||
"dist/*" | ||
], | ||
"scripts": { | ||
"codegen": "yarn run --top-level run-s 'codegen:*'", | ||
"codegen:openapi": "run-p generate-sdk generate-server", | ||
"generate-sdk": "run-p 'generate-sdk:*'", | ||
"generate-sdk:go": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g go -o ./src/main/go/generated/openapi/go-client/ --git-user-id hyperledger --git-repo-id $(echo $npm_package_name | replace @hyperledger/ \"\" -z)/src/main/go/generated/openapi/go-client --package-name $(echo $npm_package_name | replace @hyperledger/ \"\" -z) --reserved-words-mappings protected=protected --ignore-file-override ../../openapi-generator-ignore", | ||
"generate-sdk:kotlin": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g kotlin -o ./src/main/kotlin/generated/openapi/kotlin-client/ --reserved-words-mappings protected=protected --ignore-file-override ../../openapi-generator-ignore", | ||
"generate-sdk:typescript-axios": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g typescript-axios -o ./src/main/typescript/generated/openapi/typescript-axios/ --ignore-file-override ../../openapi-generator-ignore", | ||
"generate-server": "yarn run --top-level openapi-generator-cli generate -i ./src/main/json/openapi.json -g kotlin-spring -o ./src/main-server/kotlin/gen/kotlin-spring/ -c ./src/main-server/openapi-generator-config.yaml --ignore-file-override ../../openapi-generator-ignore", | ||
"watch": "npm-watch", | ||
"webpack": "npm-run-all webpack:dev", | ||
"webpack:dev": "npm-run-all webpack:dev:node webpack:dev:web", | ||
"webpack:dev:node": "webpack --env=dev --target=node --config ../../webpack.config.js", | ||
"webpack:dev:web": "webpack --env=dev --target=web --config ../../webpack.config.js" | ||
}, | ||
"dependencies": { | ||
"@hyperledger/cactus-common": "2.0.0-rc.3", | ||
"@hyperledger/cactus-core": "2.0.0-rc.3", | ||
"@hyperledger/cactus-core-api": "2.0.0-rc.3", | ||
"axios": "1.6.0", | ||
"express-openapi-validator": "5.2.0", | ||
"internal-ip": "6.2.0", | ||
"joi": "17.13.3", | ||
"node-ssh": "13.1.0", | ||
"prom-client": "15.1.3", | ||
"rxjs": "7.8.1", | ||
"temp": "0.9.4", | ||
"typescript-optional": "2.0.1" | ||
}, | ||
"devDependencies": { | ||
"@hyperledger/cactus-test-tooling": "2.0.0-rc.3", | ||
"@types/body-parser": "1.19.4", | ||
"@types/express": "4.17.21", | ||
"@types/multer": "1.4.7", | ||
"@types/temp": "0.9.1", | ||
"@types/uuid": "10.0.0", | ||
"body-parser": "1.20.2", | ||
"express": "4.19.2", | ||
"uuid": "10.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=18", | ||
"npm": ">=8" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"browserMinified": "dist/cactus-plugin-ledger-connector-corda.web.umd.min.js", | ||
"mainMinified": "dist/cactus-plugin-ledger-connector-corda.node.umd.min.js", | ||
"watch": { | ||
"codegen:openapi": { | ||
"patterns": [ | ||
"./src/main/json/openapi.json" | ||
] | ||
} | ||
} | ||
} |
177 changes: 177 additions & 0 deletions
177
...plugin-ledger-connector-daml/src/test/typescript/integration/daml-get-transaction.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
import "jest-extended"; | ||
import { DamlTestLedger } from "@hyperledger/cactus-test-tooling"; | ||
|
||
import test, { Test } from "tape-promise/tape"; | ||
import { LogLevelDesc } from "@hyperledger/cactus-common"; | ||
import { pruneDockerAllIfGithubAction } from "../../../../../../packages/cactus-test-tooling/src/main/typescript/github-actions/prune-docker-all-if-github-action" | ||
import fetch from "node-fetch"; | ||
import FormData from "form-data"; | ||
import https from "https"; | ||
import * as fs from 'fs'; | ||
|
||
const testCase = "Instantiate plugin"; | ||
const logLevel: LogLevelDesc = "TRACE"; | ||
|
||
describe("PluginLedgerConnectorDAML", () => { | ||
const damlTestLedger = new DamlTestLedger(); | ||
|
||
beforeAll(async () => { | ||
const pruning = pruneDockerAllIfGithubAction({ logLevel }); | ||
await damlTestLedger.start(); | ||
|
||
}); | ||
|
||
afterAll(async () => { | ||
await damlTestLedger.stop(); | ||
await damlTestLedger.destroy(); | ||
}); | ||
|
||
describe("DAML SIMPLE IOU TRANSACTION", () => { | ||
it("DAML SIMPLE IOU TRANSACTION", async () => { | ||
/*================== | ||
PREREQUISITES | ||
===================*/ | ||
const getPartiesInvolvedVar: string = await damlTestLedger.getPartiesInvolved(); | ||
console.log("parties involved") | ||
console.log(getPartiesInvolvedVar) | ||
//get the token for Alice | ||
const getTokenForAlice: string = damlTestLedger.getIdentifierByDisplayName(getPartiesInvolvedVar, "Alice") | ||
console.log("THIS IS THE TOKEN FOR ALICE-----") | ||
console.log(getTokenForAlice) | ||
|
||
// create a function for jwt generator | ||
const getAliceToken: string = damlTestLedger.generateJwtToken(getTokenForAlice); | ||
console.log(getAliceToken) | ||
|
||
//get the sample IOU contract using Alice | ||
const url = "http://localhost:7575/v1/query" | ||
const response = await fetch(url, { | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${getAliceToken}`, | ||
}, | ||
}); | ||
const responseBody = await response.json() | ||
console.log(responseBody.result[0].templateId) | ||
const getIouTemplate = responseBody.result[0].templateId | ||
|
||
/*================== | ||
STEP 1. Create IOU | ||
===================*/ | ||
console.log("-----CREATE IOU-----") | ||
const iouBody = { | ||
templateId: `${getIouTemplate}`, | ||
payload: { | ||
issuer: `${getTokenForAlice}`, | ||
owner: `${getTokenForAlice}`, | ||
currency: "USD", | ||
amount: "999.99", | ||
observers: [] | ||
} | ||
} | ||
const createIouUrl = "http://localhost:7575/v1/create" | ||
const responseForIOU = await fetch(createIouUrl, { | ||
method: "POST", | ||
body: JSON.stringify(iouBody), | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${getAliceToken}`, | ||
}, | ||
}); | ||
const responseForIOUResult = await responseForIOU.json() | ||
console.log(responseForIOUResult) | ||
console.log(responseForIOUResult.result.templateId) | ||
console.log(responseForIOUResult.result.contractId) | ||
let IOUtemplateId = responseForIOUResult.result.templateId | ||
let IOUcontractId = responseForIOUResult.result.contractId | ||
|
||
/*================== | ||
STEP 2. Transfer IOU to BOB | ||
===================*/ | ||
const getHashForBob: string = damlTestLedger.getIdentifierByDisplayName(getPartiesInvolvedVar, "Bob") | ||
const getBobToken: string = damlTestLedger.generateJwtToken(getHashForBob); | ||
const transferToBobBody = { | ||
templateId: `${IOUtemplateId}`, | ||
contractId: `${IOUcontractId}`, | ||
choice: `Iou_Transfer`, | ||
argument: { | ||
newOwner: `${getHashForBob}` | ||
} | ||
} | ||
|
||
// console.log(transferToBobBody) | ||
const transferUrl = "http://localhost:7575/v1/exercise" | ||
const responseForTransfer = await fetch(transferUrl, { | ||
method: "POST", | ||
body: JSON.stringify(transferToBobBody), | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${getAliceToken}`, | ||
}, | ||
}); | ||
const responseForTransferBody = await responseForTransfer.json() | ||
console.log("----transfer log") | ||
console.log(responseForTransferBody) | ||
|
||
/*================== | ||
STEP 3. Accept Transfer of IOU as BOB | ||
===================*/ | ||
const queryAsBob = await damlTestLedger.queryViaParticipant(getBobToken) | ||
console.log("query bob----") | ||
console.log(queryAsBob) | ||
|
||
let IOUTransfertemplateId = queryAsBob.result[1].templateId | ||
let IOUTransfercontractId = queryAsBob.result[1].contractId | ||
|
||
let acceptBody = { | ||
templateId: `${IOUTransfertemplateId}`, | ||
contractId: `${IOUTransfercontractId}`, | ||
choice: `IouTransfer_Accept`, | ||
argument: { | ||
newOwner: `${getBobToken}` | ||
} | ||
} | ||
const acceptUrl = "http://localhost:7575/v1/exercise" | ||
const acceptTransfer = await fetch(acceptUrl, { | ||
method: "POST", | ||
body: JSON.stringify(acceptBody), | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${getBobToken}`, | ||
}, | ||
}); | ||
const acceptTransferBody = await acceptTransfer.json() | ||
console.log("--------") | ||
console.log(acceptTransferBody) | ||
|
||
/*================== | ||
STEP 4. Check if transfer is successful by querying as BOB | ||
===================*/ | ||
let queryiou = await damlTestLedger.queryViaParticipant(getBobToken) | ||
console.log("-------iou") | ||
console.log(queryiou.result[1].templateId) | ||
let queryIOUAsBobTemplateId = queryiou.result[1].templateId | ||
|
||
let queryIouAsBobBody = { | ||
templateIds: [`${queryIOUAsBobTemplateId}`], | ||
query: {amount: 999.99}, | ||
readers: [`${getHashForBob}`] | ||
} | ||
|
||
const iouAsBobUrl = "http://localhost:7575/v1/query" | ||
const queryIouAsBobRequest = await fetch(iouAsBobUrl, { | ||
method: "POST", | ||
body: JSON.stringify(queryIouAsBobBody), | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${getBobToken}`, | ||
}, | ||
}); | ||
const bobresponse = await queryIouAsBobRequest.json() | ||
console.log("quey as bob response-----") | ||
console.log(bobresponse) | ||
|
||
}) | ||
}) | ||
}); |
Oops, something went wrong.