Skip to content

Commit

Permalink
PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nhenin committed Jan 10, 2024
1 parent 6a0229c commit 3ba0ed9
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 28 deletions.
12 changes: 7 additions & 5 deletions doc/howToDevelop.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ $ npm run clean
N.B : It is recommended to clean and build the packages before you run the tests to be sure you are playing with the most up to date version of the codebase.

```bash
$ npm run clean && npm
$ npm run clean && npm run build
```

## Unit Tests

To run the unit tests for all the packages, from the root folder you can execute the `test` command :

```bash
$ npm run test
$ npm test
```

If you want to run tests for a single package you can use the `-w` flag or execute the build command from the package folder.

```bash
# From the root folder
$ npm run clean && npm run build && npm run test -w @marlowe.io/language-core-v1
$ npm run clean && npm run build && npm test -w @marlowe.io/language-core-v1
# Or you can enter the package folder and test. You will have to clean and build properly the local package
# dependencies of this current package if you modify one of them
# e.g : `packages/language/core/v1` depends on `packages/adapter`. Be sure you have build correctly this package before runnning your test that way.
$ cd packages/language/core/v1
$ npm run test
$ npm test
```

## Integration/E2E Tests
Expand Down Expand Up @@ -124,6 +124,8 @@ LOG_DEBUG_LEVEL=false
npm run -w @marlowe.io/testing-kit genSeedPhrase
```
2. Copy/paste the words within quotes in the env file.
3. Go to one of your favorite Wallet Extension and restore a wallet with this seedphrase
4. Get a Payment Address from these Browser extensions to provision your Bank with the faucet.

#### How to add tAda to the Bank Wallet via a faucet ?

Expand Down Expand Up @@ -189,7 +191,7 @@ This project manages its changelog with [scriv](https://github.com/nedbat/scriv)

Create a new changelog entry template with

```s
```bash
$ scriv create
```

Expand Down
2 changes: 2 additions & 0 deletions packages/adapter/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ const getOnlyData = TE.bimap(

const getWithDataAndHeaders = TE.bimap(
(e: unknown) => (e instanceof Error ? e : new Error(String(e))),
// FIXME: This should be `unknown` rather than any, but it is causing multiple compile errors
(v: AxiosResponse): any => [v.headers, v.data]
);

const getWithHeaders = TE.bimap(
(e: unknown) => (e instanceof Error ? e : new Error(String(e))),
// FIXME: This should be `unknown` rather than any, but it is causing multiple compile errors
(v: AxiosResponse): any => v.headers
);

Expand Down
10 changes: 5 additions & 5 deletions packages/adapter/src/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const MINUTES = 1000 * 60;
*/
export const waitForPredicatePromise = async (
predicate: () => Promise<boolean>,
interval: number = 3_000
seconds: number = 3
): Promise<void> => {
if (await predicate()) {
// Predicate is already true, no need to wait
Expand All @@ -36,17 +36,17 @@ export const waitForPredicatePromise = async (
new Promise((resolve) => setTimeout(resolve, ms));

// Wait for the specified interval
await wait(interval);
await sleep(seconds);

// Recursive call to continue checking the predicate
await waitForPredicatePromise(predicate, interval);
await waitForPredicatePromise(predicate, seconds);
};

/**
* Block the execution flow for a given number of seconds
* @param secondes
* @returns
*/
export const sleep = (secondes: number): Promise<void> => {
return new Promise((resolve) => setTimeout(resolve, secondes * 1_000));
export const sleep = (seconds: number): Promise<void> => {
return new Promise((resolve) => setTimeout(resolve, seconds * 1_000));
};
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ describe("swap", () => {
seller: { address: sellerAddress },
deadline: pipe(addDays(Date.now(), 1), datetoTimeout),
asset: runtimeTokenToMarloweTokenValue(
seller.assetsProvisionned.tokens[0]
seller.assetsProvisioned.tokens[0]
),
},
ask: {
buyer: { role_token: "buyer" },
deadline: pipe(addDays(Date.now(), 1), datetoTimeout),
asset: runtimeTokenToMarloweTokenValue(
buyer.assetsProvisionned.tokens[0]
buyer.assetsProvisioned.tokens[0]
),
},
swapConfirmation: {
Expand Down Expand Up @@ -163,9 +163,9 @@ describe("swap", () => {
// ).payouts.withdrawn(onlyByContractIds([contractId]));
// expect(tokenProviderWithdrawn.length).toBe(1);
} catch (e) {
console.log(`catched : ${JSON.stringify(e)}`);
console.log(`caught : ${JSON.stringify(e)}`);
const error = e as AxiosError;
console.log(`catched : ${JSON.stringify(error.response?.data)}`);
console.log(`caught : ${JSON.stringify(error.response?.data)}`);
expect(true).toBe(false);
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/testing-kit/Readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Description

A Set of functionalities that supports @marlowe.io libraries for testing purposes.
A Set of utilities to help with the test of the @marlowe.io packages.
2 changes: 1 addition & 1 deletion packages/testing-kit/src/environment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type Participants = {
/**
* List of Assets provisionned By the Bank Wallet
*/
assetsProvisionned: Assets;
assetsProvisioned: Assets;
};
};

Expand Down
2 changes: 1 addition & 1 deletion packages/testing-kit/src/wallet/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export type ProvisionRequest = {
export type ProvisionResponse = {
[participant: string]: {
wallet: WalletTestAPI;
assetsProvisionned: RuntimeCore.Assets;
assetsProvisioned: RuntimeCore.Assets;
};
};

Expand Down
10 changes: 6 additions & 4 deletions packages/testing-kit/src/wallet/lucid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Lucid } from "lucid-cardano";
import { WalletAPI, mkLucidWallet } from "@marlowe.io/wallet";

import { RestClient } from "@marlowe.io/runtime-rest-client";
import { logWarning } from "../../logging.js";
import { logInfo, logWarning } from "../../logging.js";

export * as Provision from "./provisionning.js";
import * as Provision from "./provisionning.js";
Expand Down Expand Up @@ -57,6 +57,9 @@ const waitRuntimeSyncingTillCurrentWalletTip =
async (client: RestClient): Promise<void> => {
const { lucid } = di;
const currentLucidSlot = BigInt(lucid.currentSlot());
logInfo(
`Setting up a synchronization point with Runtime at SlotNo ${currentLucidSlot}`
);
await waitForPredicatePromise(
isRuntimeChainMoreAdvancedThan(client, currentLucidSlot)
);
Expand All @@ -75,10 +78,9 @@ export const isRuntimeChainMoreAdvancedThan =
if (status.tips.runtimeChain.blockHeader.slotNo >= aSlotNo) {
return true;
} else {
const delta = aSlotNo - status.tips.runtimeChain.blockHeader.slotNo;
logWarning(
`Waiting Runtime to be Synced (Delta ${
status.tips.runtimeChain.blockHeader.slotNo - aSlotNo
}) `
`Waiting Runtime to reach that point (${delta} slots behind (~${delta}s)) `
);
return false;
}
Expand Down
13 changes: 6 additions & 7 deletions packages/testing-kit/src/wallet/lucid/provisionning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,13 @@ export const provision =
.payToAddress(aDistribution[2], { lovelace: 5_000_000n }) // add a Collateral
)
);
const result: ProvisionResponse = Object.fromEntries(
distributions.map(([participant, wallet, , assetsProvisioned]) => [
participant,
{ wallet, assetsProvisioned },
])
);

var result: ProvisionResponse = {};
distributions.map(([participant, wallet, , assetsProvisionned]) => {
result[participant] = {
wallet: wallet,
assetsProvisionned: assetsProvisionned,
};
});
logDebug(`result : ${MarloweJSON.stringify(result, null, 4)}`);
const provisionTx = await mintTx.compose(transferTx).complete();

Expand Down

0 comments on commit 3ba0ed9

Please sign in to comment.