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

Chore/client integration tests #759

Merged
merged 46 commits into from
Oct 5, 2023
Merged

Conversation

Ghislain89
Copy link
Contributor

@Ghislain89 Ghislain89 commented Aug 8, 2023

This PR adds

  • the test:integration command. Invoke through pnpm run test:integration
  • GitHub Actions to run Integration tests when a change is made to @kadena/Client
  • Updates the default Jest unit test profile to ignore integration tests.
  • Integration tests to validate integration between kadena client and chainweb.

@vercel
Copy link

vercel bot commented Aug 8, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

5 Ignored Deployments
Name Status Preview Comments Updated (UTC)
alpha-docs ⬜️ Ignored (Inspect) Visit Preview Oct 5, 2023 11:17am
docs-storybook ⬜️ Ignored (Inspect) Visit Preview Oct 5, 2023 11:17am
immutable-records ⬜️ Ignored (Inspect) Visit Preview Oct 5, 2023 11:17am
react-ui ⬜️ Ignored (Inspect) Visit Preview Oct 5, 2023 11:17am
tools ⬜️ Ignored (Inspect) Visit Preview Oct 5, 2023 11:17am

chainId: '0',
guard: '5a2afbc4564b76b2c27ce5a644cab643c43663835ea0be22433b209d3351f937',
};
export const targetAccount: IAccount = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this one the same as sourceAccount?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted for the usecase that an individual wants to transfer funds to his own account on another chain. I can easily update if it's more realistic to be a different account?

@javadkh2
Copy link
Collaborator

javadkh2 commented Aug 16, 2023

Nice job Ghislain!
I will try to fix the typing issue, then we won't need to cast Pact.modules to any

@javadkh2 javadkh2 force-pushed the chore/client-integration-tests branch from 28aa26c to 6b1957c Compare September 5, 2023 09:38
@changeset-bot
Copy link

changeset-bot bot commented Sep 5, 2023

🦋 Changeset detected

Latest commit: 97849f8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@javadkh2 javadkh2 self-requested a review September 5, 2023 13:08
Copy link
Collaborator

@javadkh2 javadkh2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to update the github workflow file based on the new monorepo setup.

Copy link
Member

@alber70g alber70g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments. Only static review

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting needs to be executed. Dependencies aren't ordered alphabetically

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be done now.

let initialTargetBalance: number;

describe('Cross Chain Transfer', () => {
it('should fund the source account on chain 0', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('should fund the source account on chain 0', async () => {
it('funds the source account on chain 0', async () => {


// this is required as the source account is used to pay for gas;
// in mainnet this is not required as the gas station pays for gas
it('should fund the source account on chain 1', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('should fund the source account on chain 1', async () => {
it('funds the source account on chain 1', async () => {

expect(initialTargetBalance).toBeGreaterThanOrEqual(100);
});

it('should be able to perform a cross chain transfer', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Etc....

Suggested change
it('should be able to perform a cross chain transfer', async () => {
it('performs a cross chain transfer', async () => {

): Promise<number> {
const tr = Pact.builder
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.execution((Pact.modules as any).coin['get-balance'](account))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using Pact.modules as any you can write the Pact expression

Suggested change
.execution((Pact.modules as any).coin['get-balance'](account))
.execution(`(coin.get-balance "${account}")`)

Comment on lines +18 to +23
(Pact.modules as any).coin['transfer-create'](
sender00Account.account,
receiver,
readKeyset('ks'),
amount,
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you like this structure, generating the typings would be even better.

I think typings are available, considering the scripts in the packages/libs/client/package.json

    "pactjs:generate:contract": "pactjs contract-generate --file contracts/coin.contract.pact",
    "pactjs:retrieve:contract": "pactjs retrieve-contract --out contracts/coin.contract.pact --module coin",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried making the typings available by running the first mentioned script (I had to slightly update it) this seems to generate typings but then using pact.modules.coin doesn't appear to work. I might need a tiny little bit of help getting that to work.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't generate types for the contract here. The problem is that this file is in the client package, and we use interface merging for Pact types. This will break types in the pact.ts file itself. If we can somehow isolate this section, maybe with a separate tsconfig file, we might be able to fix it.

Comment on lines 2 to 7
export function keyFromAccount(account: Account): string {
return account.split(':')[1];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking the key from the account can only be done with k:... accounts. Would be good to do a runtime check whether the account is compatible. Even when it is, the key could've been rotated.

Suggested change
export function keyFromAccount(account: Account): string {
return account.split(':')[1];
}
export function keyFromAccount(account: Account): string {
if (!account.includes('k:')) {
throw new Error(`Not able to retrieve key from '${account}'`);
}
return account.split(':')[1];
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alber70g given that we provide a type for Account: export type Account = ${'k' | 'w'}:${string} | string;
Perhaps we could just return the account if there is no k: prefix.

@Ghislain89 Ghislain89 force-pushed the chore/client-integration-tests branch 2 times, most recently from fb8e241 to bd737cb Compare October 3, 2023 10:17
Copy link
Contributor

@webpro webpro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicks only, good stuff ✨

[1]: https://www.docker.com/
[2]: /packages/tools/heft-rig/jest.config.json
[3]: http://localhost:8080

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonus points if you add *.md or TESTING.md to the format:md script in package.json (and run that).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is done!

@@ -0,0 +1,10 @@
module.exports = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to extend from packages/tools/heft-rig/jest.config.json (and overwrite as needed like below), or not (yet)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of that, but there are quite a few settings in the central config should not be used for the integration config. It might make sense to eventually add a shared integration config if more packages perform similar tests.

@@ -33,7 +33,8 @@
"pactjs:generate:contract": "pactjs contract-generate --file contracts/coin.contract.pact",
"pactjs:retrieve:contract": "pactjs retrieve-contract --out contracts/coin.contract.pact --module coin",
"start": "ts-node --transpile-only src/index.ts",
"test": "jest"
"test": "jest",
"test:integration": "jest --silent -c ./jest.integration.config.js"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why go silent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primarily to not output all the console logging done by Kadena Client. It makes the logs generated by Jest very hard to read.

<T extends any>(data: T): T => {
console.log(tag, data);
return data;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea: move to reusable helpers? Not necessarily in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can do!

@Ghislain89 Ghislain89 requested a review from javadkh2 October 4, 2023 09:51
Copy link
Collaborator

@javadkh2 javadkh2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good enough and very valuable to merge it and have the test in the pipeline. Fixing the typing issues might require some revision of how we export contract types. For example, if we don't use interface merging, then we can easily generate types here.

@Ghislain89 Ghislain89 force-pushed the chore/client-integration-tests branch from ca62c95 to 97849f8 Compare October 5, 2023 11:14
@Ghislain89 Ghislain89 merged commit ce1d4c6 into main Oct 5, 2023
@Ghislain89 Ghislain89 deleted the chore/client-integration-tests branch October 5, 2023 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants