-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add tests #61
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 |
---|---|---|
@@ -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 () { | ||
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 @@ | |
expect(body?.id).toBeDefined() | ||
} | ||
|
||
const successfulCallTxNoRevert = ({ success, body, httpCode }) => { | ||
expect(success).toBeTrue() | ||
Check warning on line 14 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / Run E2E TestsRETRY 1: Call transaction with clauses › should simulate vet transfer
Check warning on line 14 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / Run E2E TestsRETRY 2: Call transaction with clauses › should simulate vet transfer
Check warning on line 14 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / Run E2E TestsRETRY 3: Call transaction with clauses › should simulate vet transfer
Check failure on line 14 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / Run E2E TestsCall transaction with clauses › should simulate vet transfer
Check warning on line 14 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / Run E2E TestsRETRY 1: Call transaction with clauses › should simulate function call
Check warning on line 14 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / Run E2E TestsRETRY 2: Call transaction with clauses › should simulate function call
Check warning on line 14 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / Run E2E TestsRETRY 3: Call transaction with clauses › should simulate function call
Check failure on line 14 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / Run E2E TestsCall transaction with clauses › should simulate function call
Check warning on line 14 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / Run E2E TestsRETRY 1: Call transaction with clauses › should simulate contract deployment
Check failure on line 14 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / Run E2E TestsCall transaction with clauses › should simulate contract deployment
Check failure on line 14 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / E2E Test Reporttest/thorest-api/transactions/post-call-transaction.test.js ► Call transaction with clauses ► should simulate vet transfer
Raw output
Check failure on line 14 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / E2E Test Reporttest/thorest-api/transactions/post-call-transaction.test.js ► Call transaction with clauses ► should simulate function call
Raw output
Check failure on line 14 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / E2E Test Reporttest/thorest-api/transactions/post-call-transaction.test.js ► Call transaction with clauses ► should simulate contract deployment
Raw output
|
||
expect(httpCode).toBe(200) | ||
expect(body?.txID).toBeDefined() | ||
expect(body?.vmError).toBe("") | ||
} | ||
|
||
const successfulCallTxRevert = ({ success, body, httpCode }) => { | ||
expect(success).toBeTrue() | ||
Check warning on line 21 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / Run E2E TestsRETRY 1: Call transaction with clauses › should simulate reverted function call
Check warning on line 21 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / Run E2E TestsRETRY 2: Call transaction with clauses › should simulate reverted function call
Check warning on line 21 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / Run E2E TestsRETRY 3: Call transaction with clauses › should simulate reverted function call
Check failure on line 21 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / Run E2E TestsCall transaction with clauses › should simulate reverted function call
Check failure on line 21 in test/thorest-api/transactions/setup/asserts.js GitHub Actions / E2E Test Reporttest/thorest-api/transactions/post-call-transaction.test.js ► Call transaction with clauses ► should simulate reverted function call
Raw output
|
||
expect(httpCode).toBe(200) | ||
expect(body?.txID).toBeDefined() | ||
expect(body?.vmError).not.toBe("") | ||
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 @@ | |
|
||
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.
do we need to have specific method for that or we can enhance buildTransaction one ?