-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(evm): e2e tests configuration enhancements (#2184)
* chore: changelog * chore: cleanup * chore: formatting
- Loading branch information
1 parent
57371ae
commit 5d1f87b
Showing
12 changed files
with
155 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
JSON_RPC_ENDPOINT="http://127.0.0.1:8545" | ||
MNEMONIC="guard cream sadness conduct invite crumble clock pudding hole grit liar hotel maid produce squeeze return argue turtle know drive eight casino maze host" | ||
TEST_TIMEOUT=15000 | ||
TX_WAIT_TIMEOUT=5000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
import { toBigInt } from 'ethers'; | ||
import { deployContractInfiniteLoopGas } from './utils'; | ||
import { TEST_TIMEOUT } from './setup'; | ||
|
||
describe('Infinite loop gas contract', () => { | ||
it('should fail due to out of gas error', async () => { | ||
const contract = await deployContractInfiniteLoopGas(); | ||
it( | ||
'should fail due to out of gas error', | ||
async () => { | ||
const contract = await deployContractInfiniteLoopGas(); | ||
|
||
expect(contract.counter()).resolves.toBe(toBigInt(0)); | ||
await expect(contract.counter()).resolves.toBe(toBigInt(0)); | ||
|
||
try { | ||
const tx = await contract.forever({ gasLimit: 1e6 }); | ||
await tx.wait(); | ||
throw new Error('The transaction should have failed but did not.'); | ||
} catch (error) { | ||
expect(error.message).toContain('transaction execution reverted'); | ||
} | ||
try { | ||
const tx = await contract.forever({ gasLimit: 1e6 }); | ||
await tx.wait(); | ||
throw new Error('The transaction should have failed but did not.'); | ||
} catch (error) { | ||
expect(error.message).toContain('transaction execution reverted'); | ||
} | ||
|
||
expect(contract.counter()).resolves.toBe(toBigInt(0)); | ||
}, 20e3); | ||
await expect(contract.counter()).resolves.toBe(toBigInt(0)); | ||
}, | ||
TEST_TIMEOUT, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
import { parseUnits, toBigInt, Wallet } from 'ethers'; | ||
import { account } from './setup'; | ||
import { account, TEST_TIMEOUT } from './setup'; | ||
import { deployContractTestERC20 } from './utils'; | ||
|
||
describe('ERC-20 contract tests', () => { | ||
it('should send properly', async () => { | ||
const contract = await deployContractTestERC20(); | ||
expect(contract.getAddress()).resolves.toBeDefined(); | ||
it( | ||
'should send properly', | ||
async () => { | ||
const contract = await deployContractTestERC20(); | ||
expect(contract.getAddress()).resolves.toBeDefined(); | ||
|
||
const ownerInitialBalance = parseUnits('1000000', 18); | ||
const alice = Wallet.createRandom(); | ||
const ownerInitialBalance = parseUnits('1000000', 18); | ||
const alice = Wallet.createRandom(); | ||
|
||
expect(contract.balanceOf(account)).resolves.toEqual(ownerInitialBalance); | ||
expect(contract.balanceOf(alice)).resolves.toEqual(toBigInt(0)); | ||
expect(contract.balanceOf(account)).resolves.toEqual(ownerInitialBalance); | ||
expect(contract.balanceOf(alice)).resolves.toEqual(toBigInt(0)); | ||
|
||
// send to alice | ||
const amountToSend = parseUnits('1000', 18); // contract tokens | ||
let tx = await contract.transfer(alice, amountToSend); | ||
await tx.wait(); | ||
// send to alice | ||
const amountToSend = parseUnits('1000', 18); // contract tokens | ||
let tx = await contract.transfer(alice, amountToSend); | ||
await tx.wait(); | ||
|
||
expect(contract.balanceOf(account)).resolves.toEqual(ownerInitialBalance - amountToSend); | ||
expect(contract.balanceOf(alice)).resolves.toEqual(amountToSend); | ||
}, 20e3); | ||
expect(contract.balanceOf(account)).resolves.toEqual(ownerInitialBalance - amountToSend); | ||
expect(contract.balanceOf(alice)).resolves.toEqual(amountToSend); | ||
}, | ||
TEST_TIMEOUT, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,49 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
import { parseEther, toBigInt } from 'ethers'; | ||
import { account, provider } from './setup'; | ||
import { account, provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT } from './setup'; | ||
import { alice } from './utils'; | ||
|
||
describe('native transfer', () => { | ||
it('simple transfer, balance check', async () => { | ||
const amountToSend = toBigInt(5e12) * toBigInt(1e6); // unibi | ||
const senderBalanceBefore = await provider.getBalance(account); | ||
const recipientBalanceBefore = await provider.getBalance(alice); | ||
expect(senderBalanceBefore).toBeGreaterThan(0); | ||
expect(recipientBalanceBefore).toEqual(BigInt(0)); | ||
it( | ||
'simple transfer, balance check', | ||
async () => { | ||
const amountToSend = toBigInt(5e12) * toBigInt(1e6); // unibi | ||
const senderBalanceBefore = await provider.getBalance(account); | ||
const recipientBalanceBefore = await provider.getBalance(alice); | ||
expect(senderBalanceBefore).toBeGreaterThan(0); | ||
expect(recipientBalanceBefore).toEqual(BigInt(0)); | ||
|
||
// Execute EVM transfer | ||
const transaction = { | ||
gasLimit: toBigInt(100e3), | ||
to: alice, | ||
value: amountToSend, | ||
}; | ||
const txResponse = await account.sendTransaction(transaction); | ||
await txResponse.wait(1, 10e3); | ||
expect(txResponse).toHaveProperty('blockHash'); | ||
// Execute EVM transfer | ||
const transaction = { | ||
gasLimit: toBigInt(100e3), | ||
to: alice, | ||
value: amountToSend, | ||
}; | ||
const txResponse = await account.sendTransaction(transaction); | ||
await txResponse.wait(1, TX_WAIT_TIMEOUT); | ||
expect(txResponse).toHaveProperty('blockHash'); | ||
|
||
const senderBalanceAfter = await provider.getBalance(account); | ||
const recipientBalanceAfter = await provider.getBalance(alice); | ||
const senderBalanceAfter = await provider.getBalance(account); | ||
const recipientBalanceAfter = await provider.getBalance(alice); | ||
|
||
// Assert balances with logging | ||
const tenPow12 = toBigInt(1e12); | ||
const gasUsed = transaction.gasLimit; | ||
const txCostMicronibi = amountToSend / tenPow12 + gasUsed; | ||
const txCostWei = txCostMicronibi * tenPow12; | ||
const expectedSenderWei = senderBalanceBefore - txCostWei; | ||
console.debug('DEBUG should send via transfer method %o:', { | ||
senderBalanceBefore, | ||
amountToSend, | ||
expectedSenderWei, | ||
senderBalanceAfter, | ||
txResponse, | ||
}); | ||
expect(recipientBalanceAfter).toEqual(amountToSend); | ||
const delta = senderBalanceAfter - expectedSenderWei; | ||
const deltaFromExpectation = delta >= 0 ? delta : -delta; | ||
expect(deltaFromExpectation).toBeLessThan(parseEther('0.1')); | ||
}, 20e3); | ||
// Assert balances with logging | ||
const tenPow12 = toBigInt(1e12); | ||
const gasUsed = transaction.gasLimit; | ||
const txCostMicronibi = amountToSend / tenPow12 + gasUsed; | ||
const txCostWei = txCostMicronibi * tenPow12; | ||
const expectedSenderWei = senderBalanceBefore - txCostWei; | ||
console.debug('DEBUG should send via transfer method %o:', { | ||
senderBalanceBefore, | ||
amountToSend, | ||
expectedSenderWei, | ||
senderBalanceAfter, | ||
txResponse, | ||
}); | ||
expect(recipientBalanceAfter).toEqual(amountToSend); | ||
const delta = senderBalanceAfter - expectedSenderWei; | ||
const deltaFromExpectation = delta >= 0 ? delta : -delta; | ||
expect(deltaFromExpectation).toBeLessThan(parseEther('0.1')); | ||
}, | ||
TEST_TIMEOUT, | ||
); | ||
}); |
Oops, something went wrong.