Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLT-9089: create contract bundle support #167

Merged
merged 5 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
"${workspaceFolder}/packages/runtime/client/rest/dist/esm/**/*.js",
"${workspaceFolder}/packages/runtime/core/dist/esm/**/*.js",
"${workspaceFolder}/packages/runtime/lifecycle/dist/esm/**/*.js",
"${workspaceFolder}/packages/marlowe-object/dist/esm/**/*.js"
"${workspaceFolder}/packages/marlowe-object/dist/esm/**/*.js",
"${workspaceFolder}/packages/runtime/lifecycle/test-dist/**/*.js",
"${workspaceFolder}/packages/runtime/client/rest/test-dist/**/*.js",
"${workspaceFolder}/packages/language/core/v1/test-dist/**/*.js",
"${workspaceFolder}/packages/language/examples/test-dist/**/*.js",
"${workspaceFolder}/packages/wallet/test-dist/**/*.js"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

### @marlowe.io/runtime-lifecycle

- Added support for contract bundles in the `lifecycle.contracts.createContract` function. ([PR-167](https://github.com/input-output-hk/marlowe-ts-sdk/pull/167))

69 changes: 14 additions & 55 deletions doc/howToDevelop.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,64 +59,23 @@ $ npm test

### Setting up the env Configuration File

1. Create a `./env/.env.test` at the root of the project
1. Create a `./env/.test-env.json` at the root of the project
2. Copy/Paste the following, and provide the necessary parameter

```bash
####################################################
## Provide a Runtime Instance URL (>= v0.0.5) #
####################################################
## to create an instance of a local Marlowe runtime, follow the instructions in
## the Marlowe starter kit : https://github.com/input-output-hk/ marlowe-starter-kit/blob/main/docs/preliminaries.md
MARLOWE_WEB_SERVER_URL="http://<path-to-a-runtime-instance>:<a-port>"
####################################################

#####################################################
## Provide Wallet Dependencies (Necessary for Lucid Library)
#####################################################
## Blockfrost Account : If you haven't done it before, go to https://blockfrost.io/ and create a free-tier account.
## Then, create a project and copy the project ID
BLOCKFROST_PROJECT_ID="<your-blockfrost-project-id>"
BLOCKFROST_URL="<your-blockfrost-id>"
## Network used by Blockfrost : private | preview | preprod | mainnet
NETWORK_NAME=preprod
## Bank Seed Phrase : The bank is a wallet where you provision enough tAda (>= 100 tAda) to run all
## the e2e tests without running out of money. This is your responsability to create this wallet and
## add tAda using a Faucet.
BANK_SEED_PHRASE='[
"deal",
"place",
"depart",
"sound",
"kick",
"daughter",
"diamond",
"rebel",
"update",
"shoe",
"benefit",
"useful",
"travel",
"fringe",
"culture",
"dog",
"lawsuit",
"combine",
"run",
"vanish",
"warm",
"rubber",
"quit",
"system"
]'
#####################################################

#####################################################
## Logging
#####################################################
## set to true or false if you want to log Debug Info
LOG_DEBUG_LEVEL=false
```json
{
"bank": {
"seedPhrase": "<seed phrase separated by spaces>"
},
"lucid": {
"blockfrostProjectId": "<your-blockfrost-project-id>",
"blockfrostUrl": "<your-blockfrost-url>"
},
"network": "Preprod",
"runtimeURL": "http://<path-to-a-runtime-instance>:<a-port>"
}
```

#### How to Generate a new Seed Phrase for a Bank Wallet ?

1. At the root of the project :
Expand Down
20 changes: 3 additions & 17 deletions examples/nodejs/src/marlowe-object-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,26 +567,12 @@ async function createContract(
): Promise<[ContractId, TxId]> {
const contractBundle = mkDelayPayment(schema);
const tags = mkDelayPaymentTags(schema);
// TODO: PLT-9089: Modify runtimeLifecycle.contracts.createContract to support bundle (calling createContractSources)
const contractSources =
await lifecycle.restClient.createContractSources(contractBundle);
const walletAddress = await lifecycle.wallet.getChangeAddress();
const unsignedTx = await lifecycle.restClient.buildCreateContractTx({
sourceId: contractSources.contractSourceId,
tags,
changeAddress: walletAddress,
return lifecycle.contracts.createContract({
stakeAddress: rewardAddress,
bundle: contractBundle,
tags,
minimumLovelaceUTxODeposit: 3_000_000,
version: "v1",
});
const signedCborHex = await lifecycle.wallet.signTx(unsignedTx.tx.cborHex);
await lifecycle.restClient.submitContract(
unsignedTx.contractId,
transactionWitnessSetTextEnvelope(signedCborHex)
);
const txId = contractIdToTxId(unsignedTx.contractId);
return [unsignedTx.contractId, txId];
//----------------
}

type ValidationResults = "InvalidTags" | "InvalidContract" | DelayPaymentScheme;
Expand Down
20 changes: 12 additions & 8 deletions packages/runtime/client/rest/test/endpoints/contracts.spec.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readEnvConfigurationFile } from "@marlowe.io/testing-kit";
import { mkRestClient } from "@marlowe.io/runtime-rest-client";
import { readTestConfiguration } from "@marlowe.io/testing-kit";

import console from "console";

Expand All @@ -9,8 +10,9 @@ describe("contracts endpoints", () => {
"can navigate throught some Marlowe Contracts pages" +
"(GET: /contracts/)",
async () => {
const { runtime } = await readEnvConfigurationFile();
const firstPage = await runtime.client.getContracts({
const config = await readTestConfiguration();
const restClient = mkRestClient(config.runtimeURL);
const firstPage = await restClient.getContracts({
tags: [],
partyAddresses: [],
partyRoles: [],
Expand All @@ -20,15 +22,15 @@ describe("contracts endpoints", () => {

expect(firstPage.page.next).toBeDefined();

const secondPage = await runtime.client.getContracts({
const secondPage = await restClient.getContracts({
range: firstPage.page.next,
});
expect(secondPage.contracts.length).toBe(100);
expect(secondPage.page.total).toBeGreaterThan(100);

expect(secondPage.page.next).toBeDefined();

const thirdPage = await runtime.client.getContracts({
const thirdPage = await restClient.getContracts({
range: secondPage.page.next,
});

Expand All @@ -42,8 +44,10 @@ describe("contracts endpoints", () => {
it(
"can retrieve some contract Details" + "(GET: /contracts/{contractId})",
async () => {
const { runtime } = await readEnvConfigurationFile();
const firstPage = await runtime.client.getContracts({
const config = await readTestConfiguration();
const restClient = mkRestClient(config.runtimeURL);

const firstPage = await restClient.getContracts({
tags: [],
partyAddresses: [],
partyRoles: [],
Expand All @@ -54,7 +58,7 @@ describe("contracts endpoints", () => {

await Promise.all(
firstPage.contracts.map((contract) =>
runtime.client.getContractById(contract.contractId)
restClient.getContractById(contract.contractId)
)
);
},
Expand Down
12 changes: 7 additions & 5 deletions packages/runtime/client/rest/test/endpoints/payouts.spec.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mkRestClient } from "@marlowe.io/runtime-rest-client";
import { readEnvConfigurationFile } from "@marlowe.io/testing-kit";
import { readTestConfiguration } from "@marlowe.io/testing-kit";

import console from "console";
global.console = console;
Expand All @@ -8,8 +8,10 @@ describe("payouts endpoints", () => {
it(
"can navigate throught payout headers" + "(GET: /payouts)",
async () => {
const { runtime } = await readEnvConfigurationFile();
const firstPage = await runtime.client.getPayouts({
const config = await readTestConfiguration();
const restClient = mkRestClient(config.runtimeURL);

const firstPage = await restClient.getPayouts({
contractIds: [],
roleTokens: [],
});
Expand All @@ -18,7 +20,7 @@ describe("payouts endpoints", () => {

expect(firstPage.page.next).toBeDefined();

const secondPage = await runtime.client.getPayouts({
const secondPage = await restClient.getPayouts({
contractIds: [],
roleTokens: [],
range: firstPage.page.next,
Expand All @@ -28,7 +30,7 @@ describe("payouts endpoints", () => {

expect(secondPage.page.next).toBeDefined();

const thirdPage = await runtime.client.getPayouts({
const thirdPage = await restClient.getPayouts({
contractIds: [],
roleTokens: [],
range: secondPage.page.next,
Expand Down
Loading