From 4df641f318509a624ac2c3b4caa1c9a1e433e8d4 Mon Sep 17 00:00:00 2001 From: Oleg Nikonychev Date: Wed, 29 Jan 2025 18:42:40 +0400 Subject: [PATCH 1/3] chore: changelog --- CHANGELOG.md | 1 + evm-e2e/.env_sample | 2 + .../test/contract_infinite_loop_gas.test.ts | 7 +- evm-e2e/test/contract_send_nibi.test.ts | 6 +- evm-e2e/test/debug_queries.test.ts | 6 +- evm-e2e/test/erc20.test.ts | 4 +- evm-e2e/test/eth_queries.test.ts | 31 +++---- evm-e2e/test/native_transfer.test.ts | 6 +- evm-e2e/test/nibiru_oracle.test.ts | 3 +- evm-e2e/test/setup.ts | 5 +- evm-e2e/test/tx_receipt.test.ts | 8 +- evm-e2e/test/utils.ts | 82 +++++++++---------- 12 files changed, 86 insertions(+), 75 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53514b6fc..a853af033 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,7 @@ needed to include double quotes around the hexadecimal string. - [#2176](https://github.com/NibiruChain/nibiru/pull/2176) - tests(evm): add dirty state tests from code4rena audit - [#2180](https://github.com/NibiruChain/nibiru/pull/2180) - fix(evm): apply gas consumption across the entire EVM codebase at `CallContractWithInput` - [#2183](https://github.com/NibiruChain/nibiru/pull/2183) - fix(evm): bank keeper extension gas meter type +- [#2184](https://github.com/NibiruChain/nibiru/pull/2184) - test(evm): e2e tests configuration enhancements - #### Nibiru EVM | Before Audit 2 - 2024-12-06 diff --git a/evm-e2e/.env_sample b/evm-e2e/.env_sample index 98bebd6b2..f0492b948 100644 --- a/evm-e2e/.env_sample +++ b/evm-e2e/.env_sample @@ -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 diff --git a/evm-e2e/test/contract_infinite_loop_gas.test.ts b/evm-e2e/test/contract_infinite_loop_gas.test.ts index 6508e0dce..3975a0387 100644 --- a/evm-e2e/test/contract_infinite_loop_gas.test.ts +++ b/evm-e2e/test/contract_infinite_loop_gas.test.ts @@ -1,12 +1,13 @@ 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(); - expect(contract.counter()).resolves.toBe(toBigInt(0)); + await expect(contract.counter()).resolves.toBe(toBigInt(0)); try { const tx = await contract.forever({ gasLimit: 1e6 }); @@ -16,6 +17,6 @@ describe('Infinite loop gas contract', () => { 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 * 2); }); diff --git a/evm-e2e/test/contract_send_nibi.test.ts b/evm-e2e/test/contract_send_nibi.test.ts index fa474b434..ea69d2786 100644 --- a/evm-e2e/test/contract_send_nibi.test.ts +++ b/evm-e2e/test/contract_send_nibi.test.ts @@ -11,7 +11,7 @@ */ import { describe, expect, it } from '@jest/globals'; import { parseEther, toBigInt, Wallet } from 'ethers'; -import { account, provider } from './setup'; +import {account, provider, TX_WAIT_TIMEOUT} from './setup'; import { deployContractSendNibi } from './utils'; async function testSendNibi(method: 'sendViaTransfer' | 'sendViaSend' | 'sendViaCall', weiToSend: bigint) { @@ -23,7 +23,7 @@ async function testSendNibi(method: 'sendViaTransfer' | 'sendViaSend' | 'sendVia expect(recipientBalanceBefore).toEqual(BigInt(0)); const tx = await contract[method](recipient, { value: weiToSend }); - const receipt = await tx.wait(1, 5e3); + const receipt = await tx.wait(1, TX_WAIT_TIMEOUT); const tenPow12 = toBigInt(1e12); const txCostMicronibi = weiToSend / tenPow12 + receipt.gasUsed; @@ -52,7 +52,7 @@ async function testSendNibi(method: 'sendViaTransfer' | 'sendViaSend' | 'sendVia } describe('Send NIBI via smart contract', () => { - const TIMEOUT_MS = 20e3; + const TIMEOUT_MS = TX_WAIT_TIMEOUT * 2; it( 'method sendViaTransfer', async () => { diff --git a/evm-e2e/test/debug_queries.test.ts b/evm-e2e/test/debug_queries.test.ts index e58901c31..953ef0529 100644 --- a/evm-e2e/test/debug_queries.test.ts +++ b/evm-e2e/test/debug_queries.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it, beforeAll } from '@jest/globals'; import { TransactionReceipt, parseEther } from 'ethers'; -import { provider } from './setup'; +import {provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT} from './setup'; import { alice, deployContractTestERC20, hexify } from './utils'; import { TestERC20__factory } from '../types'; @@ -18,14 +18,14 @@ describe('debug queries', () => { // Execute some contract TX const txResponse = await contract.transfer(alice, parseEther('0.01')); - await txResponse.wait(1, 5e3); + await txResponse.wait(1, TX_WAIT_TIMEOUT); const receipt: TransactionReceipt = await provider.getTransactionReceipt(txResponse.hash); txHash = txResponse.hash; txIndex = txResponse.index; blockNumber = receipt.blockNumber; blockHash = receipt.blockHash; - }, 20e3); + }, TEST_TIMEOUT); it('debug_traceBlockByNumber', async () => { const traceResult = await provider.send('debug_traceBlockByNumber', [ diff --git a/evm-e2e/test/erc20.test.ts b/evm-e2e/test/erc20.test.ts index 1405253ea..03e8fccbe 100644 --- a/evm-e2e/test/erc20.test.ts +++ b/evm-e2e/test/erc20.test.ts @@ -1,6 +1,6 @@ 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', () => { @@ -21,5 +21,5 @@ describe('ERC-20 contract tests', () => { expect(contract.balanceOf(account)).resolves.toEqual(ownerInitialBalance - amountToSend); expect(contract.balanceOf(alice)).resolves.toEqual(amountToSend); - }, 20e3); + }, TEST_TIMEOUT); }); diff --git a/evm-e2e/test/eth_queries.test.ts b/evm-e2e/test/eth_queries.test.ts index 13bcb13a0..671819fa1 100644 --- a/evm-e2e/test/eth_queries.test.ts +++ b/evm-e2e/test/eth_queries.test.ts @@ -1,21 +1,21 @@ import { describe, expect, it, jest } from '@jest/globals'; -import { parseEther, keccak256, AbiCoder } from 'ethers'; -import { account, provider } from './setup'; +import {parseEther, keccak256, AbiCoder, ethers} from 'ethers'; +import {account, provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT} from './setup'; import { INTRINSIC_TX_GAS, alice, deployContractTestERC20, deployContractSendNibi, hexify, - sendTestNibi, + sendTestNibi, numberToHex, } from './utils'; describe('eth queries', () => { - jest.setTimeout(15e3); + jest.setTimeout(TEST_TIMEOUT); it('eth_accounts', async () => { const accounts = await provider.listAccounts(); - expect(accounts).not.toHaveLength(0); + expect(accounts).not.toBeNull() }); it('eth_estimateGas', async () => { @@ -54,7 +54,7 @@ describe('eth queries', () => { }); it('eth_getBlockByNumber, eth_getBlockByHash', async () => { - const blockNumber = 1; + const blockNumber = "latest"; const blockByNumber = await provider.send('eth_getBlockByNumber', [blockNumber, false]); expect(blockByNumber).toBeDefined(); expect(blockByNumber).toHaveProperty('hash'); @@ -66,14 +66,14 @@ describe('eth queries', () => { }); it('eth_getBlockTransactionCountByHash', async () => { - const blockNumber = 1; + const blockNumber = "latest"; const block = await provider.send('eth_getBlockByNumber', [blockNumber, false]); const txCount = await provider.send('eth_getBlockTransactionCountByHash', [block.hash]); expect(parseInt(txCount)).toBeGreaterThanOrEqual(0); }); it('eth_getBlockTransactionCountByNumber', async () => { - const blockNumber = 1; + const blockNumber = "latest"; const txCount = await provider.send('eth_getBlockTransactionCountByNumber', [blockNumber]); expect(parseInt(txCount)).toBeGreaterThanOrEqual(0); }); @@ -86,11 +86,12 @@ describe('eth queries', () => { }); it('eth_getFilterChanges', async () => { + const currentBlock = await provider.getBlockNumber() // Deploy ERC-20 contract const contract = await deployContractTestERC20(); const contractAddr = await contract.getAddress(); const filter = { - fromBlock: '0x1', + fromBlock: numberToHex(currentBlock), address: contractAddr, }; // Create the filter for a contract @@ -99,7 +100,7 @@ describe('eth queries', () => { // Execute some contract TX const tx = await contract.transfer(alice, parseEther('0.01')); - await tx.wait(1, 5e3); + await tx.wait(1, TX_WAIT_TIMEOUT); await new Promise((resolve) => setTimeout(resolve, 3000)); // Assert logs @@ -114,16 +115,17 @@ describe('eth queries', () => { }); it('eth_getFilterLogs', async () => { + const currentBlock = await provider.getBlockNumber() // Deploy ERC-20 contract const contract = await deployContractTestERC20(); const contractAddr = await contract.getAddress(); const filter = { - fromBlock: '0x1', + fromBlock: numberToHex(currentBlock), address: contractAddr, }; // Execute some contract TX const tx = await contract.transfer(alice, parseEther('0.01')); - await tx.wait(1, 5e3); + await tx.wait(1, TX_WAIT_TIMEOUT); await new Promise((resolve) => setTimeout(resolve, 3000)); // Create the filter for a contract @@ -139,16 +141,17 @@ describe('eth queries', () => { }); it('eth_getLogs', async () => { + const currentBlock = await provider.getBlockNumber() // Deploy ERC-20 contract const contract = await deployContractTestERC20(); const contractAddr = await contract.getAddress(); const filter = { - fromBlock: '0x1', + fromBlock: numberToHex(currentBlock), address: contractAddr, }; // Execute some contract TX const tx = await contract.transfer(alice, parseEther('0.01')); - await tx.wait(1, 5e3); + await tx.wait(1, TX_WAIT_TIMEOUT); await new Promise((resolve) => setTimeout(resolve, 3000)); // Assert logs diff --git a/evm-e2e/test/native_transfer.test.ts b/evm-e2e/test/native_transfer.test.ts index 475ab270b..2ded40392 100644 --- a/evm-e2e/test/native_transfer.test.ts +++ b/evm-e2e/test/native_transfer.test.ts @@ -1,6 +1,6 @@ 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', () => { @@ -18,7 +18,7 @@ describe('native transfer', () => { value: amountToSend, }; const txResponse = await account.sendTransaction(transaction); - await txResponse.wait(1, 10e3); + await txResponse.wait(1, TX_WAIT_TIMEOUT); expect(txResponse).toHaveProperty('blockHash'); const senderBalanceAfter = await provider.getBalance(account); @@ -41,5 +41,5 @@ describe('native transfer', () => { const delta = senderBalanceAfter - expectedSenderWei; const deltaFromExpectation = delta >= 0 ? delta : -delta; expect(deltaFromExpectation).toBeLessThan(parseEther('0.1')); - }, 20e3); + }, TEST_TIMEOUT); }); diff --git a/evm-e2e/test/nibiru_oracle.test.ts b/evm-e2e/test/nibiru_oracle.test.ts index 28a5f05be..5a8b19e2c 100644 --- a/evm-e2e/test/nibiru_oracle.test.ts +++ b/evm-e2e/test/nibiru_oracle.test.ts @@ -1,6 +1,7 @@ import { expect, test } from '@jest/globals'; import { toBigInt } from 'ethers'; import { deployContractNibiruOracleChainLinkLike } from './utils'; +import {TEST_TIMEOUT} from "./setup"; test('NibiruOracleChainLinkLike implements ChainLink AggregatorV3Interface', async () => { const { oraclePair, contract } = await deployContractNibiruOracleChainLinkLike(); @@ -37,4 +38,4 @@ test('NibiruOracleChainLinkLike implements ChainLink AggregatorV3Interface', asy expect(answeredInRound).toEqual(420n); expect(answer).toEqual(genesisEthUsdPrice * toBigInt(1e8)); } -}); +}, TEST_TIMEOUT); diff --git a/evm-e2e/test/setup.ts b/evm-e2e/test/setup.ts index ec2fe24b7..c99c4cd52 100644 --- a/evm-e2e/test/setup.ts +++ b/evm-e2e/test/setup.ts @@ -5,5 +5,8 @@ config(); const provider = new ethers.JsonRpcProvider(process.env.JSON_RPC_ENDPOINT); const account = Wallet.fromPhrase(process.env.MNEMONIC, provider); +const TEST_TIMEOUT = Number(process.env.TEST_TIMEOUT) || 15000; +const TX_WAIT_TIMEOUT = Number(process.env.TX_WAIT_TIMEOUT) || 5000; + +export { account, provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT}; -export { account, provider }; diff --git a/evm-e2e/test/tx_receipt.test.ts b/evm-e2e/test/tx_receipt.test.ts index 7a95cd995..ee995fc84 100644 --- a/evm-e2e/test/tx_receipt.test.ts +++ b/evm-e2e/test/tx_receipt.test.ts @@ -1,11 +1,11 @@ import { describe, expect, it, jest } from '@jest/globals'; import { ethers, TransactionReceipt, Log } from 'ethers'; -import { account } from './setup'; -import { deployContractEventsEmitter, deployContractTransactionReverter, TENPOW12 } from './utils'; +import {account, TEST_TIMEOUT} from './setup'; +import { deployContractEventsEmitter } from './utils'; import { TestERC20__factory } from '../types'; describe('Transaction Receipt Tests', () => { - jest.setTimeout(15e3); + jest.setTimeout(TEST_TIMEOUT); let recipient = ethers.Wallet.createRandom().address; @@ -24,7 +24,7 @@ describe('Transaction Receipt Tests', () => { it('contract deployment receipt', async () => { const factory = new TestERC20__factory(account); - const deployTx = await factory.deploy({ maxFeePerGas: TENPOW12 }); + const deployTx = await factory.deploy(); const receipt = await deployTx.deploymentTransaction().wait(); assertBaseReceiptFields(receipt); diff --git a/evm-e2e/test/utils.ts b/evm-e2e/test/utils.ts index dbf8f4c1c..5ccf47d18 100644 --- a/evm-e2e/test/utils.ts +++ b/evm-e2e/test/utils.ts @@ -1,11 +1,11 @@ -import { account } from './setup'; -import { ContractTransactionResponse, parseEther, toBigInt, TransactionRequest, Wallet } from 'ethers'; +import {account, provider, TX_WAIT_TIMEOUT} from './setup'; +import {ContractTransactionResponse, parseEther, toBigInt, TransactionRequest, Wallet } from 'ethers'; import { - InifiniteLoopGas__factory, - SendNibi__factory, - TestERC20__factory, - EventsEmitter__factory, - TransactionReverter__factory, + InifiniteLoopGas__factory, + SendNibi__factory, + TestERC20__factory, + EventsEmitter__factory, + TransactionReverter__factory, NibiruOracleChainLinkLike__factory, NibiruOracleChainLinkLike, } from '../types'; @@ -13,60 +13,56 @@ import { export const alice = Wallet.createRandom(); export const hexify = (x: number): string => { - return '0x' + x.toString(16); + return '0x' + x.toString(16); }; -/** 10 to the power of 12 */ -export const TENPOW12 = toBigInt(1e12); - export const INTRINSIC_TX_GAS: bigint = 21000n; export const deployContractTestERC20 = async () => { - const factory = new TestERC20__factory(account); - const contract = await factory.deploy({ maxFeePerGas: TENPOW12 }); - await contract.waitForDeployment(); - return contract; + const factory = new TestERC20__factory(account); + const contract = await factory.deploy(); + await contract.waitForDeployment(); + return contract; }; export const deployContractSendNibi = async () => { - const factory = new SendNibi__factory(account); - const contract = await factory.deploy({ maxFeePerGas: TENPOW12 }); - await contract.waitForDeployment(); - return contract; + const factory = new SendNibi__factory(account); + const contract = await factory.deploy(); + await contract.waitForDeployment(); + return contract; }; export const deployContractInfiniteLoopGas = async () => { - const factory = new InifiniteLoopGas__factory(account); - const contract = await factory.deploy({ maxFeePerGas: TENPOW12 }); - await contract.waitForDeployment(); - return contract; + const factory = new InifiniteLoopGas__factory(account); + const contract = await factory.deploy(); + await contract.waitForDeployment(); + return contract; }; export const deployContractEventsEmitter = async () => { - const factory = new EventsEmitter__factory(account); - const contract = await factory.deploy(); - await contract.waitForDeployment(); - return contract; + const factory = new EventsEmitter__factory(account); + const contract = await factory.deploy(); + await contract.waitForDeployment(); + return contract; }; export const deployContractTransactionReverter = async () => { - const factory = new TransactionReverter__factory(account); - const contract = await factory.deploy(); - await contract.waitForDeployment(); - return contract; + const factory = new TransactionReverter__factory(account); + const contract = await factory.deploy(); + await contract.waitForDeployment(); + return contract; }; export const sendTestNibi = async () => { - const transaction: TransactionRequest = { - gasLimit: toBigInt(100e3), - to: alice, - value: parseEther('0.01'), - maxFeePerGas: TENPOW12, - }; - const txResponse = await account.sendTransaction(transaction); - await txResponse.wait(1, 10e3); - console.log(txResponse); - return txResponse; + const transaction: TransactionRequest = { + gasLimit: toBigInt(100e3), + to: alice, + value: parseEther('0.01'), + }; + const txResponse = await account.sendTransaction(transaction); + await txResponse.wait(1, TX_WAIT_TIMEOUT); + console.log(txResponse); + return txResponse; }; export const deployContractNibiruOracleChainLinkLike = async (): Promise<{ @@ -81,3 +77,7 @@ export const deployContractNibiruOracleChainLinkLike = async (): Promise<{ await contract.waitForDeployment(); return { oraclePair, contract }; }; + +export const numberToHex = (num: Number) => { + return "0x" + num.toString(16) +} \ No newline at end of file From e9e35b832ae5ecdc05c53b779dc14569cc74d6ef Mon Sep 17 00:00:00 2001 From: Oleg Nikonychev Date: Wed, 29 Jan 2025 18:47:56 +0400 Subject: [PATCH 2/3] chore: cleanup --- .../test/contract_infinite_loop_gas.test.ts | 2 +- evm-e2e/test/contract_send_nibi.test.ts | 115 +++++++++--------- 2 files changed, 58 insertions(+), 59 deletions(-) diff --git a/evm-e2e/test/contract_infinite_loop_gas.test.ts b/evm-e2e/test/contract_infinite_loop_gas.test.ts index 3975a0387..602e0dfd0 100644 --- a/evm-e2e/test/contract_infinite_loop_gas.test.ts +++ b/evm-e2e/test/contract_infinite_loop_gas.test.ts @@ -18,5 +18,5 @@ describe('Infinite loop gas contract', () => { } await expect(contract.counter()).resolves.toBe(toBigInt(0)); - }, TEST_TIMEOUT * 2); + }, TEST_TIMEOUT); }); diff --git a/evm-e2e/test/contract_send_nibi.test.ts b/evm-e2e/test/contract_send_nibi.test.ts index ea69d2786..f29cfe07b 100644 --- a/evm-e2e/test/contract_send_nibi.test.ts +++ b/evm-e2e/test/contract_send_nibi.test.ts @@ -9,74 +9,73 @@ * The methods tested are from the smart contract, * "evm-e2e/contracts/SendReceiveNibi.sol". */ -import { describe, expect, it } from '@jest/globals'; -import { parseEther, toBigInt, Wallet } from 'ethers'; -import {account, provider, TX_WAIT_TIMEOUT} from './setup'; -import { deployContractSendNibi } from './utils'; +import {describe, expect, it} from '@jest/globals'; +import {parseEther, toBigInt, Wallet} from 'ethers'; +import {account, provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT} from './setup'; +import {deployContractSendNibi} from './utils'; async function testSendNibi(method: 'sendViaTransfer' | 'sendViaSend' | 'sendViaCall', weiToSend: bigint) { - const contract = await deployContractSendNibi(); - const recipient = Wallet.createRandom(); + const contract = await deployContractSendNibi(); + const recipient = Wallet.createRandom(); - const ownerBalanceBefore = await provider.getBalance(account); - const recipientBalanceBefore = await provider.getBalance(recipient); - expect(recipientBalanceBefore).toEqual(BigInt(0)); + const ownerBalanceBefore = await provider.getBalance(account); + const recipientBalanceBefore = await provider.getBalance(recipient); + expect(recipientBalanceBefore).toEqual(BigInt(0)); - const tx = await contract[method](recipient, { value: weiToSend }); - const receipt = await tx.wait(1, TX_WAIT_TIMEOUT); + const tx = await contract[method](recipient, {value: weiToSend}); + const receipt = await tx.wait(1, TX_WAIT_TIMEOUT); - const tenPow12 = toBigInt(1e12); - const txCostMicronibi = weiToSend / tenPow12 + receipt.gasUsed; - const txCostWei = txCostMicronibi * tenPow12; - const expectedOwnerWei = ownerBalanceBefore - txCostWei; + const tenPow12 = toBigInt(1e12); + const txCostMicronibi = weiToSend / tenPow12 + receipt.gasUsed; + const txCostWei = txCostMicronibi * tenPow12; + const expectedOwnerWei = ownerBalanceBefore - txCostWei; - const ownerBalanceAfter = await provider.getBalance(account); - const recipientBalanceAfter = await provider.getBalance(recipient); + const ownerBalanceAfter = await provider.getBalance(account); + const recipientBalanceAfter = await provider.getBalance(recipient); - console.debug(`DEBUG method ${method} %o:`, { - ownerBalanceBefore, - weiToSend, - expectedOwnerWei, - ownerBalanceAfter, - recipientBalanceBefore, - recipientBalanceAfter, - gasUsed: receipt.gasUsed, - gasPrice: `${receipt.gasPrice.toString()}`, - to: receipt.to, - from: receipt.from, - }); - expect(recipientBalanceAfter).toBe(weiToSend); - const delta = ownerBalanceAfter - expectedOwnerWei; - const deltaFromExpectation = delta >= 0 ? delta : -delta; - expect(deltaFromExpectation).toBeLessThan(parseEther('0.1')); + console.debug(`DEBUG method ${method} %o:`, { + ownerBalanceBefore, + weiToSend, + expectedOwnerWei, + ownerBalanceAfter, + recipientBalanceBefore, + recipientBalanceAfter, + gasUsed: receipt.gasUsed, + gasPrice: `${receipt.gasPrice.toString()}`, + to: receipt.to, + from: receipt.from, + }); + expect(recipientBalanceAfter).toBe(weiToSend); + const delta = ownerBalanceAfter - expectedOwnerWei; + const deltaFromExpectation = delta >= 0 ? delta : -delta; + expect(deltaFromExpectation).toBeLessThan(parseEther('0.1')); } describe('Send NIBI via smart contract', () => { - const TIMEOUT_MS = TX_WAIT_TIMEOUT * 2; - it( - 'method sendViaTransfer', - async () => { - const weiToSend: bigint = toBigInt(5e12) * toBigInt(1e6); - await testSendNibi('sendViaTransfer', weiToSend); - }, - TIMEOUT_MS, - ); + it( + 'method sendViaTransfer', + async () => { + const weiToSend: bigint = toBigInt(5e12) * toBigInt(1e6); + await testSendNibi('sendViaTransfer', weiToSend); + }, + TEST_TIMEOUT, + ); - it( - 'method sendViaSend', - async () => { - const weiToSend: bigint = toBigInt(100e12) * toBigInt(1e6); - await testSendNibi('sendViaSend', weiToSend); - }, - TIMEOUT_MS, - ); + it( + 'method sendViaSend', + async () => { + const weiToSend: bigint = toBigInt(100e12) * toBigInt(1e6); + await testSendNibi('sendViaSend', weiToSend); + }, + TEST_TIMEOUT, + ); - it( - 'method sendViaCall', - async () => { - const weiToSend: bigint = toBigInt(100e12) * toBigInt(1e6); - await testSendNibi('sendViaCall', weiToSend); - }, - TIMEOUT_MS, - ); + it( + 'method sendViaCall', + async () => { + const weiToSend: bigint = toBigInt(100e12) * toBigInt(1e6); + await testSendNibi('sendViaCall', weiToSend); + }, + TEST_TIMEOUT, + ); }); From 63fc7edd33f7fd7a6b155e849b0b09c44e6810c2 Mon Sep 17 00:00:00 2001 From: Oleg Nikonychev Date: Wed, 29 Jan 2025 18:56:04 +0400 Subject: [PATCH 3/3] chore: formatting --- .../test/contract_infinite_loop_gas.test.ts | 28 +++-- evm-e2e/test/contract_send_nibi.test.ts | 114 +++++++++--------- evm-e2e/test/debug_queries.test.ts | 2 +- evm-e2e/test/erc20.test.ts | 34 +++--- evm-e2e/test/eth_queries.test.ts | 21 ++-- evm-e2e/test/native_transfer.test.ts | 76 ++++++------ evm-e2e/test/nibiru_oracle.test.ts | 66 +++++----- evm-e2e/test/setup.ts | 3 +- evm-e2e/test/tx_receipt.test.ts | 2 +- evm-e2e/test/utils.ts | 78 ++++++------ 10 files changed, 220 insertions(+), 204 deletions(-) diff --git a/evm-e2e/test/contract_infinite_loop_gas.test.ts b/evm-e2e/test/contract_infinite_loop_gas.test.ts index 602e0dfd0..ac1350811 100644 --- a/evm-e2e/test/contract_infinite_loop_gas.test.ts +++ b/evm-e2e/test/contract_infinite_loop_gas.test.ts @@ -4,19 +4,23 @@ 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(); - await 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'); + } - await expect(contract.counter()).resolves.toBe(toBigInt(0)); - }, TEST_TIMEOUT); + await expect(contract.counter()).resolves.toBe(toBigInt(0)); + }, + TEST_TIMEOUT, + ); }); diff --git a/evm-e2e/test/contract_send_nibi.test.ts b/evm-e2e/test/contract_send_nibi.test.ts index f29cfe07b..da322fba8 100644 --- a/evm-e2e/test/contract_send_nibi.test.ts +++ b/evm-e2e/test/contract_send_nibi.test.ts @@ -9,73 +9,73 @@ * The methods tested are from the smart contract, * "evm-e2e/contracts/SendReceiveNibi.sol". */ -import {describe, expect, it} from '@jest/globals'; -import {parseEther, toBigInt, Wallet} from 'ethers'; -import {account, provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT} from './setup'; -import {deployContractSendNibi} from './utils'; +import { describe, expect, it } from '@jest/globals'; +import { parseEther, toBigInt, Wallet } from 'ethers'; +import { account, provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT } from './setup'; +import { deployContractSendNibi } from './utils'; async function testSendNibi(method: 'sendViaTransfer' | 'sendViaSend' | 'sendViaCall', weiToSend: bigint) { - const contract = await deployContractSendNibi(); - const recipient = Wallet.createRandom(); + const contract = await deployContractSendNibi(); + const recipient = Wallet.createRandom(); - const ownerBalanceBefore = await provider.getBalance(account); - const recipientBalanceBefore = await provider.getBalance(recipient); - expect(recipientBalanceBefore).toEqual(BigInt(0)); + const ownerBalanceBefore = await provider.getBalance(account); + const recipientBalanceBefore = await provider.getBalance(recipient); + expect(recipientBalanceBefore).toEqual(BigInt(0)); - const tx = await contract[method](recipient, {value: weiToSend}); - const receipt = await tx.wait(1, TX_WAIT_TIMEOUT); + const tx = await contract[method](recipient, { value: weiToSend }); + const receipt = await tx.wait(1, TX_WAIT_TIMEOUT); - const tenPow12 = toBigInt(1e12); - const txCostMicronibi = weiToSend / tenPow12 + receipt.gasUsed; - const txCostWei = txCostMicronibi * tenPow12; - const expectedOwnerWei = ownerBalanceBefore - txCostWei; + const tenPow12 = toBigInt(1e12); + const txCostMicronibi = weiToSend / tenPow12 + receipt.gasUsed; + const txCostWei = txCostMicronibi * tenPow12; + const expectedOwnerWei = ownerBalanceBefore - txCostWei; - const ownerBalanceAfter = await provider.getBalance(account); - const recipientBalanceAfter = await provider.getBalance(recipient); + const ownerBalanceAfter = await provider.getBalance(account); + const recipientBalanceAfter = await provider.getBalance(recipient); - console.debug(`DEBUG method ${method} %o:`, { - ownerBalanceBefore, - weiToSend, - expectedOwnerWei, - ownerBalanceAfter, - recipientBalanceBefore, - recipientBalanceAfter, - gasUsed: receipt.gasUsed, - gasPrice: `${receipt.gasPrice.toString()}`, - to: receipt.to, - from: receipt.from, - }); - expect(recipientBalanceAfter).toBe(weiToSend); - const delta = ownerBalanceAfter - expectedOwnerWei; - const deltaFromExpectation = delta >= 0 ? delta : -delta; - expect(deltaFromExpectation).toBeLessThan(parseEther('0.1')); + console.debug(`DEBUG method ${method} %o:`, { + ownerBalanceBefore, + weiToSend, + expectedOwnerWei, + ownerBalanceAfter, + recipientBalanceBefore, + recipientBalanceAfter, + gasUsed: receipt.gasUsed, + gasPrice: `${receipt.gasPrice.toString()}`, + to: receipt.to, + from: receipt.from, + }); + expect(recipientBalanceAfter).toBe(weiToSend); + const delta = ownerBalanceAfter - expectedOwnerWei; + const deltaFromExpectation = delta >= 0 ? delta : -delta; + expect(deltaFromExpectation).toBeLessThan(parseEther('0.1')); } describe('Send NIBI via smart contract', () => { - it( - 'method sendViaTransfer', - async () => { - const weiToSend: bigint = toBigInt(5e12) * toBigInt(1e6); - await testSendNibi('sendViaTransfer', weiToSend); - }, - TEST_TIMEOUT, - ); + it( + 'method sendViaTransfer', + async () => { + const weiToSend: bigint = toBigInt(5e12) * toBigInt(1e6); + await testSendNibi('sendViaTransfer', weiToSend); + }, + TEST_TIMEOUT, + ); - it( - 'method sendViaSend', - async () => { - const weiToSend: bigint = toBigInt(100e12) * toBigInt(1e6); - await testSendNibi('sendViaSend', weiToSend); - }, - TEST_TIMEOUT, - ); + it( + 'method sendViaSend', + async () => { + const weiToSend: bigint = toBigInt(100e12) * toBigInt(1e6); + await testSendNibi('sendViaSend', weiToSend); + }, + TEST_TIMEOUT, + ); - it( - 'method sendViaCall', - async () => { - const weiToSend: bigint = toBigInt(100e12) * toBigInt(1e6); - await testSendNibi('sendViaCall', weiToSend); - }, - TEST_TIMEOUT, - ); + it( + 'method sendViaCall', + async () => { + const weiToSend: bigint = toBigInt(100e12) * toBigInt(1e6); + await testSendNibi('sendViaCall', weiToSend); + }, + TEST_TIMEOUT, + ); }); diff --git a/evm-e2e/test/debug_queries.test.ts b/evm-e2e/test/debug_queries.test.ts index 953ef0529..3c6468504 100644 --- a/evm-e2e/test/debug_queries.test.ts +++ b/evm-e2e/test/debug_queries.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it, beforeAll } from '@jest/globals'; import { TransactionReceipt, parseEther } from 'ethers'; -import {provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT} from './setup'; +import { provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT } from './setup'; import { alice, deployContractTestERC20, hexify } from './utils'; import { TestERC20__factory } from '../types'; diff --git a/evm-e2e/test/erc20.test.ts b/evm-e2e/test/erc20.test.ts index 03e8fccbe..573f23d20 100644 --- a/evm-e2e/test/erc20.test.ts +++ b/evm-e2e/test/erc20.test.ts @@ -1,25 +1,29 @@ import { describe, expect, it } from '@jest/globals'; import { parseUnits, toBigInt, Wallet } from 'ethers'; -import {account, TEST_TIMEOUT} 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); - }, TEST_TIMEOUT); + expect(contract.balanceOf(account)).resolves.toEqual(ownerInitialBalance - amountToSend); + expect(contract.balanceOf(alice)).resolves.toEqual(amountToSend); + }, + TEST_TIMEOUT, + ); }); diff --git a/evm-e2e/test/eth_queries.test.ts b/evm-e2e/test/eth_queries.test.ts index 671819fa1..fc8ccac0b 100644 --- a/evm-e2e/test/eth_queries.test.ts +++ b/evm-e2e/test/eth_queries.test.ts @@ -1,13 +1,14 @@ import { describe, expect, it, jest } from '@jest/globals'; -import {parseEther, keccak256, AbiCoder, ethers} from 'ethers'; -import {account, provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT} from './setup'; +import { parseEther, keccak256, AbiCoder, ethers } from 'ethers'; +import { account, provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT } from './setup'; import { INTRINSIC_TX_GAS, alice, deployContractTestERC20, deployContractSendNibi, hexify, - sendTestNibi, numberToHex, + sendTestNibi, + numberToHex, } from './utils'; describe('eth queries', () => { @@ -15,7 +16,7 @@ describe('eth queries', () => { it('eth_accounts', async () => { const accounts = await provider.listAccounts(); - expect(accounts).not.toBeNull() + expect(accounts).not.toBeNull(); }); it('eth_estimateGas', async () => { @@ -54,7 +55,7 @@ describe('eth queries', () => { }); it('eth_getBlockByNumber, eth_getBlockByHash', async () => { - const blockNumber = "latest"; + const blockNumber = 'latest'; const blockByNumber = await provider.send('eth_getBlockByNumber', [blockNumber, false]); expect(blockByNumber).toBeDefined(); expect(blockByNumber).toHaveProperty('hash'); @@ -66,14 +67,14 @@ describe('eth queries', () => { }); it('eth_getBlockTransactionCountByHash', async () => { - const blockNumber = "latest"; + const blockNumber = 'latest'; const block = await provider.send('eth_getBlockByNumber', [blockNumber, false]); const txCount = await provider.send('eth_getBlockTransactionCountByHash', [block.hash]); expect(parseInt(txCount)).toBeGreaterThanOrEqual(0); }); it('eth_getBlockTransactionCountByNumber', async () => { - const blockNumber = "latest"; + const blockNumber = 'latest'; const txCount = await provider.send('eth_getBlockTransactionCountByNumber', [blockNumber]); expect(parseInt(txCount)).toBeGreaterThanOrEqual(0); }); @@ -86,7 +87,7 @@ describe('eth queries', () => { }); it('eth_getFilterChanges', async () => { - const currentBlock = await provider.getBlockNumber() + const currentBlock = await provider.getBlockNumber(); // Deploy ERC-20 contract const contract = await deployContractTestERC20(); const contractAddr = await contract.getAddress(); @@ -115,7 +116,7 @@ describe('eth queries', () => { }); it('eth_getFilterLogs', async () => { - const currentBlock = await provider.getBlockNumber() + const currentBlock = await provider.getBlockNumber(); // Deploy ERC-20 contract const contract = await deployContractTestERC20(); const contractAddr = await contract.getAddress(); @@ -141,7 +142,7 @@ describe('eth queries', () => { }); it('eth_getLogs', async () => { - const currentBlock = await provider.getBlockNumber() + const currentBlock = await provider.getBlockNumber(); // Deploy ERC-20 contract const contract = await deployContractTestERC20(); const contractAddr = await contract.getAddress(); diff --git a/evm-e2e/test/native_transfer.test.ts b/evm-e2e/test/native_transfer.test.ts index 2ded40392..c6c0193f8 100644 --- a/evm-e2e/test/native_transfer.test.ts +++ b/evm-e2e/test/native_transfer.test.ts @@ -1,45 +1,49 @@ import { describe, expect, it } from '@jest/globals'; import { parseEther, toBigInt } from 'ethers'; -import {account, provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT} 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, TX_WAIT_TIMEOUT); - 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')); - }, TEST_TIMEOUT); + // 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, + ); }); diff --git a/evm-e2e/test/nibiru_oracle.test.ts b/evm-e2e/test/nibiru_oracle.test.ts index 5a8b19e2c..5695a60b7 100644 --- a/evm-e2e/test/nibiru_oracle.test.ts +++ b/evm-e2e/test/nibiru_oracle.test.ts @@ -1,41 +1,45 @@ import { expect, test } from '@jest/globals'; import { toBigInt } from 'ethers'; import { deployContractNibiruOracleChainLinkLike } from './utils'; -import {TEST_TIMEOUT} from "./setup"; +import { TEST_TIMEOUT } from './setup'; -test('NibiruOracleChainLinkLike implements ChainLink AggregatorV3Interface', async () => { - const { oraclePair, contract } = await deployContractNibiruOracleChainLinkLike(); +test( + 'NibiruOracleChainLinkLike implements ChainLink AggregatorV3Interface', + async () => { + const { oraclePair, contract } = await deployContractNibiruOracleChainLinkLike(); - const oracleAddr = await contract.getAddress(); - expect(oracleAddr).not.toBeFalsy(); + const oracleAddr = await contract.getAddress(); + expect(oracleAddr).not.toBeFalsy(); - const decimals = await contract.decimals(); - expect(decimals).toEqual(BigInt(8)); + const decimals = await contract.decimals(); + expect(decimals).toEqual(BigInt(8)); - const description = await contract.description(); - expect(description).toEqual(`Nibiru Oracle ChainLink-like price feed for ${oraclePair}`); + const description = await contract.description(); + expect(description).toEqual(`Nibiru Oracle ChainLink-like price feed for ${oraclePair}`); - const version = await contract.version(); - expect(version).toEqual(1n); + const version = await contract.version(); + expect(version).toEqual(1n); - // latestRoundData - const genesisEthUsdPrice = 2000n; - { - const { roundId, answer, startedAt, updatedAt, answeredInRound } = await contract.latestRoundData(); - expect(roundId).toEqual(0n); // price is from genesis block - expect(startedAt).toBeGreaterThan(1n); - expect(updatedAt).toBeGreaterThan(1n); - expect(answeredInRound).toEqual(420n); - expect(answer).toEqual(genesisEthUsdPrice * toBigInt(1e8)); - } + // latestRoundData + const genesisEthUsdPrice = 2000n; + { + const { roundId, answer, startedAt, updatedAt, answeredInRound } = await contract.latestRoundData(); + expect(roundId).toEqual(0n); // price is from genesis block + expect(startedAt).toBeGreaterThan(1n); + expect(updatedAt).toBeGreaterThan(1n); + expect(answeredInRound).toEqual(420n); + expect(answer).toEqual(genesisEthUsdPrice * toBigInt(1e8)); + } - // getRoundData - { - const { roundId, answer, startedAt, updatedAt, answeredInRound } = await contract.getRoundData(0n); - expect(roundId).toEqual(0n); // price is from genesis block - expect(startedAt).toBeGreaterThan(1n); - expect(updatedAt).toBeGreaterThan(1n); - expect(answeredInRound).toEqual(420n); - expect(answer).toEqual(genesisEthUsdPrice * toBigInt(1e8)); - } -}, TEST_TIMEOUT); + // getRoundData + { + const { roundId, answer, startedAt, updatedAt, answeredInRound } = await contract.getRoundData(0n); + expect(roundId).toEqual(0n); // price is from genesis block + expect(startedAt).toBeGreaterThan(1n); + expect(updatedAt).toBeGreaterThan(1n); + expect(answeredInRound).toEqual(420n); + expect(answer).toEqual(genesisEthUsdPrice * toBigInt(1e8)); + } + }, + TEST_TIMEOUT, +); diff --git a/evm-e2e/test/setup.ts b/evm-e2e/test/setup.ts index c99c4cd52..09fdc0784 100644 --- a/evm-e2e/test/setup.ts +++ b/evm-e2e/test/setup.ts @@ -8,5 +8,4 @@ const account = Wallet.fromPhrase(process.env.MNEMONIC, provider); const TEST_TIMEOUT = Number(process.env.TEST_TIMEOUT) || 15000; const TX_WAIT_TIMEOUT = Number(process.env.TX_WAIT_TIMEOUT) || 5000; -export { account, provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT}; - +export { account, provider, TEST_TIMEOUT, TX_WAIT_TIMEOUT }; diff --git a/evm-e2e/test/tx_receipt.test.ts b/evm-e2e/test/tx_receipt.test.ts index ee995fc84..c42f1bb41 100644 --- a/evm-e2e/test/tx_receipt.test.ts +++ b/evm-e2e/test/tx_receipt.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it, jest } from '@jest/globals'; import { ethers, TransactionReceipt, Log } from 'ethers'; -import {account, TEST_TIMEOUT} from './setup'; +import { account, TEST_TIMEOUT } from './setup'; import { deployContractEventsEmitter } from './utils'; import { TestERC20__factory } from '../types'; diff --git a/evm-e2e/test/utils.ts b/evm-e2e/test/utils.ts index 5ccf47d18..b6879d49a 100644 --- a/evm-e2e/test/utils.ts +++ b/evm-e2e/test/utils.ts @@ -1,11 +1,11 @@ -import {account, provider, TX_WAIT_TIMEOUT} from './setup'; -import {ContractTransactionResponse, parseEther, toBigInt, TransactionRequest, Wallet } from 'ethers'; +import { account, provider, TX_WAIT_TIMEOUT } from './setup'; +import { ContractTransactionResponse, parseEther, toBigInt, TransactionRequest, Wallet } from 'ethers'; import { - InifiniteLoopGas__factory, - SendNibi__factory, - TestERC20__factory, - EventsEmitter__factory, - TransactionReverter__factory, + InifiniteLoopGas__factory, + SendNibi__factory, + TestERC20__factory, + EventsEmitter__factory, + TransactionReverter__factory, NibiruOracleChainLinkLike__factory, NibiruOracleChainLinkLike, } from '../types'; @@ -13,56 +13,56 @@ import { export const alice = Wallet.createRandom(); export const hexify = (x: number): string => { - return '0x' + x.toString(16); + return '0x' + x.toString(16); }; export const INTRINSIC_TX_GAS: bigint = 21000n; export const deployContractTestERC20 = async () => { - const factory = new TestERC20__factory(account); - const contract = await factory.deploy(); - await contract.waitForDeployment(); - return contract; + const factory = new TestERC20__factory(account); + const contract = await factory.deploy(); + await contract.waitForDeployment(); + return contract; }; export const deployContractSendNibi = async () => { - const factory = new SendNibi__factory(account); - const contract = await factory.deploy(); - await contract.waitForDeployment(); - return contract; + const factory = new SendNibi__factory(account); + const contract = await factory.deploy(); + await contract.waitForDeployment(); + return contract; }; export const deployContractInfiniteLoopGas = async () => { - const factory = new InifiniteLoopGas__factory(account); - const contract = await factory.deploy(); - await contract.waitForDeployment(); - return contract; + const factory = new InifiniteLoopGas__factory(account); + const contract = await factory.deploy(); + await contract.waitForDeployment(); + return contract; }; export const deployContractEventsEmitter = async () => { - const factory = new EventsEmitter__factory(account); - const contract = await factory.deploy(); - await contract.waitForDeployment(); - return contract; + const factory = new EventsEmitter__factory(account); + const contract = await factory.deploy(); + await contract.waitForDeployment(); + return contract; }; export const deployContractTransactionReverter = async () => { - const factory = new TransactionReverter__factory(account); - const contract = await factory.deploy(); - await contract.waitForDeployment(); - return contract; + const factory = new TransactionReverter__factory(account); + const contract = await factory.deploy(); + await contract.waitForDeployment(); + return contract; }; export const sendTestNibi = async () => { - const transaction: TransactionRequest = { - gasLimit: toBigInt(100e3), - to: alice, - value: parseEther('0.01'), - }; - const txResponse = await account.sendTransaction(transaction); - await txResponse.wait(1, TX_WAIT_TIMEOUT); - console.log(txResponse); - return txResponse; + const transaction: TransactionRequest = { + gasLimit: toBigInt(100e3), + to: alice, + value: parseEther('0.01'), + }; + const txResponse = await account.sendTransaction(transaction); + await txResponse.wait(1, TX_WAIT_TIMEOUT); + console.log(txResponse); + return txResponse; }; export const deployContractNibiruOracleChainLinkLike = async (): Promise<{ @@ -79,5 +79,5 @@ export const deployContractNibiruOracleChainLinkLike = async (): Promise<{ }; export const numberToHex = (num: Number) => { - return "0x" + num.toString(16) -} \ No newline at end of file + return '0x' + num.toString(16); +};