Skip to content

Commit

Permalink
Refactor test to work with cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
spacesailor24 committed Jun 22, 2023
1 parent 288fb00 commit b0682eb
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 78 deletions.
52 changes: 30 additions & 22 deletions fixtures/contracts/NegativeNumbers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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,
},
]),
);
});
});

0 comments on commit b0682eb

Please sign in to comment.