From b0682eb517cd8ac84484658198834c7e2f265660 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Wed, 21 Jun 2023 16:39:27 -1000 Subject: [PATCH] Refactor test to work with cypress --- fixtures/contracts/NegativeNumbers.sol | 52 ++++---- .../contract_negative_numbers.test.ts | 116 +++++++++--------- 2 files changed, 90 insertions(+), 78 deletions(-) diff --git a/fixtures/contracts/NegativeNumbers.sol b/fixtures/contracts/NegativeNumbers.sol index 09831c41319..4c11a6b5449 100644 --- a/fixtures/contracts/NegativeNumbers.sol +++ b/fixtures/contracts/NegativeNumbers.sol @@ -2,31 +2,39 @@ pragma solidity 0.8.13; contract NegativeNumbers { - int256 public storedNegativeNumber; + int256 public storedNegativeNumber; - event OneNegativeNumber (int256 one); - event OneNegativeNumberIndexed (int256 indexed one); - event TwoNegativeNumbers (int256 one, int256 two); - event TwoNegativeNumbersIndexed (int256 indexed one, int indexed two); - event OtherNegativeNumbers(uint256 positive, int256 negative, string str); - event OtherNegativeNumbersIndexed(uint256 indexed positive, int256 indexed negative, string str); + event OneNegativeNumber(int256 one); + event OneNegativeNumberIndexed(int256 indexed one); + event TwoNegativeNumbers(int256 one, int256 two); + event TwoNegativeNumbersIndexed(int256 indexed one, int256 indexed two); + event OtherNegativeNumbers(uint256 positive, int256 negative, string str); + event OtherNegativeNumbersIndexed( + uint256 indexed positive, + int256 indexed negative, + string str + ); - constructor(int256 number) { - storedNegativeNumber = number; - } + constructor(int256 number) { + storedNegativeNumber = number; + } - function oneNegativeNumber(int256 number) public { - emit OneNegativeNumber(number); - emit OneNegativeNumberIndexed(number); - } + function oneNegativeNumber(int256 number) public { + emit OneNegativeNumber(number); + emit OneNegativeNumberIndexed(number); + } - function twoNegativeNumbers(int256 number, int256 number2) public { - emit TwoNegativeNumbers(number, number2); - emit TwoNegativeNumbersIndexed(number, number2); - } + function twoNegativeNumbers(int256 number, int256 number2) public { + emit TwoNegativeNumbers(number, number2); + emit TwoNegativeNumbersIndexed(number, number2); + } - function otherNegativeNumbers(int256 number, int256 number2, string calldata str) public { - emit OtherNegativeNumbers(uint256(number), number2, str); - emit OtherNegativeNumbersIndexed(uint256(number), number2, str); - } + function otherNegativeNumbers( + int256 number, + int256 number2, + string calldata str + ) public { + emit OtherNegativeNumbers(uint256(number), number2, str); + emit OtherNegativeNumbersIndexed(uint256(number), number2, str); + } } diff --git a/packages/web3-eth-contract/test/integration/contract_negative_numbers.test.ts b/packages/web3-eth-contract/test/integration/contract_negative_numbers.test.ts index 5e0382eb7ae..345d01d3473 100644 --- a/packages/web3-eth-contract/test/integration/contract_negative_numbers.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_negative_numbers.test.ts @@ -94,34 +94,36 @@ describe('Contract - NegativeNumbers.sol', () => { .twoNegativeNumbers(storedNegativeNumber, secondNegativeNumber) .send(sendOptions); - expect(transactionReceipt.logs).toMatchObject([ - { - address: expect.any(String), - topics: ['0xfaa997e4b16dcde196bbb99868e16fa934a0b4c1f019e494d9fbffb5abc46fc2'], - data: '0xffffffffffffffffffffffffffffffff80000000000000000000000000000001ffffffffffd6a416919bf9968e000000000000000048c26d7f0da3fa91bf56f8', - blockNumber: expect.any(BigInt), - transactionHash: expect.any(String), - transactionIndex: expect.any(BigInt), - blockHash: expect.any(String), - logIndex: BigInt(0), - removed: false, - }, - { - address: expect.any(String), - topics: [ - '0x0204c97becd72594486cf753e30e8acfc9951ee663e404bc858e3d10b80da99b', - '0xffffffffffffffffffffffffffffffff80000000000000000000000000000001', - '0xffffffffffd6a416919bf9968e000000000000000048c26d7f0da3fa91bf56f8', - ], - data: '0x', - blockNumber: expect.any(BigInt), - transactionHash: expect.any(String), - transactionIndex: expect.any(BigInt), - blockHash: expect.any(String), - logIndex: BigInt(1), - removed: false, - }, - ]); + expect(transactionReceipt.logs).toEqual( + expect.objectContaining([ + { + address: expect.any(String), + topics: ['0xfaa997e4b16dcde196bbb99868e16fa934a0b4c1f019e494d9fbffb5abc46fc2'], + data: '0xffffffffffffffffffffffffffffffff80000000000000000000000000000001ffffffffffd6a416919bf9968e000000000000000048c26d7f0da3fa91bf56f8', + blockNumber: expect.any(BigInt), + transactionHash: expect.any(String), + transactionIndex: expect.any(BigInt), + blockHash: expect.any(String), + logIndex: BigInt(0), + removed: false, + }, + { + address: expect.any(String), + topics: [ + '0x0204c97becd72594486cf753e30e8acfc9951ee663e404bc858e3d10b80da99b', + '0xffffffffffffffffffffffffffffffff80000000000000000000000000000001', + '0xffffffffffd6a416919bf9968e000000000000000048c26d7f0da3fa91bf56f8', + ], + data: '0x', + blockNumber: expect.any(BigInt), + transactionHash: expect.any(String), + transactionIndex: expect.any(BigInt), + blockHash: expect.any(String), + logIndex: BigInt(1), + removed: false, + }, + ]), + ); }); it('should return storedNegativeNumber when calling otherNegativeNumbers(storedNegativeNumber, secondNegativeNumber)', async () => { @@ -132,33 +134,35 @@ describe('Contract - NegativeNumbers.sol', () => { .otherNegativeNumbers(storedNegativeNumber, secondNegativeNumber, 'fooBar') .send(sendOptions); - expect(transactionReceipt.logs).toMatchObject([ - { - address: expect.any(String), - topics: ['0x2e1fb99ee1b27b6491b2d46a54ac8daca82f2da6810e4b8eed4d634f78fa6948'], - data: '0xffffffffffffffffffffffffffffffff80000000000000000000000000000001ffffffffffd6a416919bf9968e000000000000000048c26d7f0da3fa91bf56f800000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000006666f6f4261720000000000000000000000000000000000000000000000000000', - blockNumber: expect.any(BigInt), - transactionHash: expect.any(String), - transactionIndex: expect.any(BigInt), - blockHash: expect.any(String), - logIndex: BigInt(0), - removed: false, - }, - { - address: expect.any(String), - topics: [ - '0x0e29b573959c1b6ffd5e16886385ec1732e187cc5ac10e8faceb5e02a1c7b50b', - '0xffffffffffffffffffffffffffffffff80000000000000000000000000000001', - '0xffffffffffd6a416919bf9968e000000000000000048c26d7f0da3fa91bf56f8', - ], - data: '0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006666f6f4261720000000000000000000000000000000000000000000000000000', - blockNumber: expect.any(BigInt), - transactionHash: expect.any(String), - transactionIndex: expect.any(BigInt), - blockHash: expect.any(String), - logIndex: BigInt(1), - removed: false, - }, - ]); + expect(transactionReceipt.logs).toEqual( + expect.objectContaining([ + { + address: expect.any(String), + topics: ['0x2e1fb99ee1b27b6491b2d46a54ac8daca82f2da6810e4b8eed4d634f78fa6948'], + data: '0xffffffffffffffffffffffffffffffff80000000000000000000000000000001ffffffffffd6a416919bf9968e000000000000000048c26d7f0da3fa91bf56f800000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000006666f6f4261720000000000000000000000000000000000000000000000000000', + blockNumber: expect.any(BigInt), + transactionHash: expect.any(String), + transactionIndex: expect.any(BigInt), + blockHash: expect.any(String), + logIndex: BigInt(0), + removed: false, + }, + { + address: expect.any(String), + topics: [ + '0x0e29b573959c1b6ffd5e16886385ec1732e187cc5ac10e8faceb5e02a1c7b50b', + '0xffffffffffffffffffffffffffffffff80000000000000000000000000000001', + '0xffffffffffd6a416919bf9968e000000000000000048c26d7f0da3fa91bf56f8', + ], + data: '0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006666f6f4261720000000000000000000000000000000000000000000000000000', + blockNumber: expect.any(BigInt), + transactionHash: expect.any(String), + transactionIndex: expect.any(BigInt), + blockHash: expect.any(String), + logIndex: BigInt(1), + removed: false, + }, + ]), + ); }); });