-
Notifications
You must be signed in to change notification settings - Fork 4
Add tests #61
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
base: main
Are you sure you want to change the base?
Add tests #61
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| NODE_URLS=http://localhost:8669,http://localhost:8679,http://localhost:8689 | ||
| NODE_URLS=http://localhost:8669 | ||
| PRIVATE_KEYS= | ||
| MNEMONIC="denial kitchen pet squirrel other broom bar gas better priority spoil cross" | ||
| NETWORK_TYPE=default-private | ||
| NETWORK_TYPE=solo | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,6 +154,30 @@ class ThorWallet { | |
| } | ||
| } | ||
|
|
||
| buildCallTransaction = async (clauses, options) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to have specific method for that or we can enhance buildTransaction one ? |
||
| const bestBlockRef = await getBlockRef('best') | ||
| const genesisBlock = await Client.raw.getBlock('0') | ||
|
|
||
| if (!genesisBlock.success || !genesisBlock.body?.id) { | ||
| throw new Error('Could not get best block') | ||
| } | ||
|
|
||
| return { | ||
| id: "0x0000000000000000000000000000000000000000000000000000000000000000", | ||
| chainTag: parseInt(genesisBlock.body.id.slice(-2), 16), | ||
| blockRef: options?.blockRef ?? "0x0000000000000000", | ||
| expiration: 10, | ||
| clauses: clauses, | ||
| gasPriceCoef: 0, | ||
| gas: 1_000_000, | ||
| origin: options?.origin ?? null, | ||
| delegator: null, | ||
| nonce: options?.nonce ?? "0x0", | ||
| dependsOn: options?.dependsOn ?? null, | ||
| meta: null | ||
| } | ||
| } | ||
|
|
||
| signTransaction = async (transaction, delegationSignature) => { | ||
| const signingHash = transaction.getTransactionHash() | ||
| const signature = Secp256k1.sign(signingHash.bytes, this.privateKey) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import { ThorWallet, generateAddress } from '../../../src/wallet' | ||
| import { TransactionDataDrivenFlow } from './setup/transaction-data-driven-flow' | ||
| import { successfulCallTxNoRevert, successfulCallTxRevert } from './setup/asserts' | ||
| import { SimpleCounter__factory as SimpleCounter } from '../../../typechain-types' | ||
|
|
||
| /** | ||
| * @group api | ||
| * @group transactions | ||
| */ | ||
| describe('Call transaction with clauses', function () { | ||
| const wallet = ThorWallet.withFunds() | ||
|
|
||
| let counter | ||
|
|
||
| beforeAll(async () => { | ||
| await wallet.waitForFunding() | ||
| counter = await wallet.deployContract( | ||
| SimpleCounter.bytecode, | ||
| SimpleCounter.abi, | ||
| ) | ||
| }) | ||
|
|
||
| it.e2eTest('should simulate vet transfer', 'all', async function () { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we can add: mixed clauses (like contract call + vet transfer), tx delegation and not enough gas cases. As this should follow the same validation rules |
||
| const txBody = await wallet.buildCallTransaction([ | ||
| { | ||
| to: await generateAddress(), | ||
| value: `0x${BigInt(5).toString(16)}`, | ||
| data: '0x', | ||
| }, | ||
| { | ||
| to: await generateAddress(), | ||
| value: `0x${BigInt(6).toString(16)}`, | ||
| data: '0x', | ||
| }, | ||
| ], { | ||
| origin: wallet.address | ||
| }) | ||
|
|
||
| const testPlan = { | ||
| postTxStep: { | ||
| tx: txBody, | ||
| expectedResult: successfulCallTxNoRevert, | ||
| }, | ||
| } | ||
|
|
||
| const ddt = new TransactionDataDrivenFlow(testPlan) | ||
| await ddt.callTransaction() | ||
| }) | ||
|
|
||
| it.e2eTest('should simulate function call', 'all', async function () { | ||
| const incrementCounter = '0x5b34b966' | ||
|
|
||
| const txBody = await wallet.buildCallTransaction([ | ||
| { | ||
| value: "0x0", | ||
| data: incrementCounter, | ||
| to: counter.address, | ||
| }, | ||
| ], { | ||
| origin: wallet.address | ||
| }) | ||
|
|
||
| const testPlan = { | ||
| postTxStep: { | ||
| tx: txBody, | ||
| expectedResult: successfulCallTxNoRevert, | ||
| }, | ||
| } | ||
|
|
||
| const ddt = new TransactionDataDrivenFlow(testPlan) | ||
| await ddt.callTransaction() | ||
| }) | ||
|
|
||
| it.e2eTest('should simulate reverted function call', 'all', async function () { | ||
| const incrementCounter = '0x5b34b966' | ||
|
|
||
| const txBody = await wallet.buildCallTransaction([ | ||
| { | ||
| value: "0x0", | ||
| data: incrementCounter, | ||
| to: counter.address, | ||
| }, | ||
| ], { | ||
| origin: "0x000000000000000000000000000000000000dEaD" | ||
| }) | ||
|
|
||
| const testPlan = { | ||
| postTxStep: { | ||
| tx: txBody, | ||
| expectedResult: successfulCallTxRevert, | ||
| }, | ||
| } | ||
|
|
||
| const ddt = new TransactionDataDrivenFlow(testPlan) | ||
| await ddt.callTransaction() | ||
| }) | ||
|
|
||
| it.e2eTest('should simulate contract deployment', 'all', async function () { | ||
|
|
||
| const txBody = await wallet.buildCallTransaction([ | ||
| { | ||
| value: "0x0", | ||
| data: SimpleCounter.bytecode, | ||
| to: null, | ||
| }, | ||
| ], { | ||
| origin: wallet.address | ||
| }) | ||
|
|
||
| const testPlan = { | ||
| postTxStep: { | ||
| tx: txBody, | ||
| expectedResult: successfulCallTxNoRevert, | ||
| }, | ||
| } | ||
|
|
||
| const ddt = new TransactionDataDrivenFlow(testPlan) | ||
| await ddt.callTransaction() | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,20 @@ const successfulPostTx = ({ success, body, httpCode }) => { | |
| expect(body?.id).toBeDefined() | ||
| } | ||
|
|
||
| const successfulCallTxNoRevert = ({ success, body, httpCode }) => { | ||
| expect(success).toBeTrue() | ||
| expect(httpCode).toBe(200) | ||
| expect(body?.txID).toBeDefined() | ||
| expect(body?.vmError).toBe("") | ||
| } | ||
|
|
||
| const successfulCallTxRevert = ({ success, body, httpCode }) => { | ||
| expect(success).toBeTrue() | ||
| expect(httpCode).toBe(200) | ||
| expect(body?.txID).toBeDefined() | ||
| expect(body?.vmError).not.toBe("") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wonder if we can add specific error we look for ? as this just checks it is not empty |
||
| } | ||
|
|
||
| const revertedPostTx = ( | ||
| { success, body, httpCode, httpMessage }, | ||
| expectedErrorMsg, | ||
|
|
@@ -121,6 +135,8 @@ const checkTransactionLogSuccess = (input, block, tx, transferClauses) => { | |
|
|
||
| export { | ||
| successfulPostTx, | ||
| successfulCallTxNoRevert, | ||
| successfulCallTxRevert, | ||
| revertedPostTx, | ||
| compareSentTxWithCreatedTx, | ||
| checkDelegatedTransaction, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we dont need to push this one, as it is just local config