Skip to content

feature: add initial integration tests#27

Open
AlonzoRicardo wants to merge 12 commits intotetherto:developfrom
AlonzoRicardo:feature/add-integration-tests
Open

feature: add initial integration tests#27
AlonzoRicardo wants to merge 12 commits intotetherto:developfrom
AlonzoRicardo:feature/add-integration-tests

Conversation

@AlonzoRicardo
Copy link
Copy Markdown
Contributor

Description

Motivation and Context

Related Issue

PR fixes the following issue:

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

package.json Outdated
"test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage"
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=tests/integration",
"test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --testPathIgnorePatterns=tests/integration",
"compile:tron": "npx hardhat compile --network tron --config tests/artifacts/hardhat.config.cjs",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of compiling its smart contract, it would be better to include the artifact directly in the repo like we are doing in wallet-evm:
https://github.com/tetherto/wdk-wallet-evm/blob/main/tests/artifacts/TestToken.json

package.json Outdated
Comment on lines +24 to +25
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=tests/integration",
"test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --testPathIgnorePatterns=tests/integration",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

npm test should run both unit and integration tests:

Suggested change
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=tests/integration",
"test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --testPathIgnorePatterns=tests/integration",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
"test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage",

package.json Outdated
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=tests/integration",
"test:coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --testPathIgnorePatterns=tests/integration",
"compile:tron": "npx hardhat compile --network tron --config tests/artifacts/hardhat.config.cjs",
"test:integration": "npm run compile:tron && cross-env NODE_OPTIONS=--experimental-vm-modules jest tests/integration/module.test.js --testTimeout 120000 --transform '{}' --runInBand",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't really get any benefit from using the --runInBand option. Actually, it might slow down the execution time of the tests when they are run on our machines since this option makes them run serially on a single thread. It might make sense to enable this flag in the ci/cd of the project though, since it may reduce the running time of the build workflow.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm also not sure about the purpose of the --transform option, i couldn't even find it in the documentation.

package.json Outdated
"bare.js",
"tests/**/*.js"
"tests/**/*.js",
"tests/artifacts/hardhat.config.cjs"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need to ignore this file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

By including the artifact in the repo, hardhat becomes quite useless. We should be able to get rid of it completely, along with the layerzero plugins.

expect(isValid).toBe(true)
}, TIMEOUT)

test('should convert a full account to read-only and perform balance, quote and receipt operations', async () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's no need for this test.

for (const acc of [acc0, acc1]) {
expect(acc.keyPair.privateKey).toBeFalsy()

await expect(acc.sign('Hello, world!')).rejects.toThrow()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should verify that the 'sendTransaction' and the 'transfer' method start throwing as well after disposing the wallet. Also, always assert against a specific error message or pattern instead of just requiring the method to throw:

Suggested change
await expect(acc.sign('Hello, world!')).rejects.toThrow()
await expect(acc.sign('Hello, world!')).rejects.toThrow('The expected error message...')

disposableManager.dispose()

for (const acc of [acc0, acc1]) {
expect(acc.keyPair.privateKey).toBeFalsy()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The private key should be null after disposing the account (see here):

Suggested change
expect(acc.keyPair.privateKey).toBeFalsy()
expect(acc.keyPair.privateKey).toBe(null)


const TRANSFER = {
token: setup.testTokenAddress,
recipient: await (await walletManager.getAccount(1)).getAddress(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's use a different address here too.

/**
* Blocks until the Tron node is producing blocks.
*
* @param {TronWeb} tronWeb
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we want to provide doc comments for testing components as well, then we must do it properly. So, either we get rid of them or we provide the missing descriptions for arguments and return values in this method and the methods below.

@AlonzoRicardo AlonzoRicardo force-pushed the feature/add-integration-tests branch from 1d4fe40 to 4ffb32b Compare March 10, 2026 00:32
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.

2 participants