Skip to content
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

[test] Fix assertion on arrays of BigNumbers #222

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/bridge/BridgeTracking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('Bridge Tracking test', () => {
await roninValidatorSet.connect(coinbase).wrapUpEpoch();
});
period = await roninValidatorSet.currentPeriod();
expect(await roninValidatorSet.getBridgeOperators()).eql(candidates.map((v) => v.bridgeOperator.address));
expect(await roninValidatorSet.getBridgeOperators()).deep.equal(candidates.map((v) => v.bridgeOperator.address));
});

after(async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/bridge/GatewayPauseEnforcer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe('Ronin Gateway V2 test', () => {
await roninValidatorSet.connect(coinbase).wrapUpEpoch();
});
period = await roninValidatorSet.currentPeriod();
expect(await roninValidatorSet.getBridgeOperators()).eql(candidates.map((v) => v.bridgeOperator.address));
expect(await roninValidatorSet.getBridgeOperators()).deep.equal(candidates.map((v) => v.bridgeOperator.address));
});

after(async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/bridge/RoninGatewayV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('Ronin Gateway V2 test', () => {
await roninValidatorSet.connect(coinbase).wrapUpEpoch();
});
period = await roninValidatorSet.currentPeriod();
expect(await roninValidatorSet.getBridgeOperators()).eql(candidates.map((v) => v.bridgeOperator.address));
expect(await roninValidatorSet.getBridgeOperators()).deep.equal(candidates.map((v) => v.bridgeOperator.address));
});

after(async () => {
Expand Down
22 changes: 11 additions & 11 deletions test/governance-admin/GovernanceAdmin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('Governance Admin test', () => {
const latestBOset = await governanceAdmin.lastSyncedBridgeOperatorSetInfo();
expect(latestBOset.period).eq(0);
expect(latestBOset.epoch).eq(0);
expect(latestBOset.operators).eql([]);
expect(latestBOset.operators).deep.equal([]);
});

it('Should be able to vote bridge operators', async () => {
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('Governance Admin test', () => {
const latestBOset = await governanceAdmin.lastSyncedBridgeOperatorSetInfo();
expect(latestBOset.period).eq(ballot.period);
expect(latestBOset.epoch).eq(ballot.epoch);
expect(latestBOset.operators).eql(ballot.operators);
expect(latestBOset.operators).deep.equal(ballot.operators);
});

it('Should be able relay vote bridge operators', async () => {
Expand All @@ -195,11 +195,11 @@ describe('Governance Admin test', () => {
await mainchainGovernanceAdmin.connect(relayer).relayBridgeOperators(ballot, signatures);
expect(await mainchainGovernanceAdmin.bridgeOperatorsRelayed(ballot.period, ballot.epoch)).to.true;
const bridgeOperators = await bridgeContract.getBridgeOperators();
expect([...bridgeOperators].sort(compareAddrs)).eql(ballot.operators);
expect([...bridgeOperators].sort(compareAddrs)).deep.equal(ballot.operators);
const latestBOset = await mainchainGovernanceAdmin.lastSyncedBridgeOperatorSetInfo();
expect(latestBOset.period).eq(ballot.period);
expect(latestBOset.epoch).eq(ballot.epoch);
expect(latestBOset.operators).eql(ballot.operators);
expect(latestBOset.operators).deep.equal(ballot.operators);
});

it('Should not able to relay again', async () => {
Expand Down Expand Up @@ -307,18 +307,18 @@ describe('Governance Admin test', () => {
expect(lastLength).not.eq(ballot.operators.length);
expect(latestBOset.period).eq(ballot.period);
expect(latestBOset.epoch).eq(ballot.epoch);
expect(latestBOset.operators).eql(ballot.operators);
expect(latestBOset.operators).deep.equal(ballot.operators);
});

it('Should be able relay vote bridge operators', async () => {
const [, signatures] = await governanceAdmin.getBridgeOperatorVotingSignatures(ballot.period, ballot.epoch);
await mainchainGovernanceAdmin.connect(relayer).relayBridgeOperators(ballot, signatures);
const bridgeOperators = await bridgeContract.getBridgeOperators();
expect([...bridgeOperators].sort(compareAddrs)).eql(ballot.operators);
expect([...bridgeOperators].sort(compareAddrs)).deep.equal(ballot.operators);
const latestBOset = await mainchainGovernanceAdmin.lastSyncedBridgeOperatorSetInfo();
expect(latestBOset.period).eq(ballot.period);
expect(latestBOset.epoch).eq(ballot.epoch);
expect(latestBOset.operators).eql(ballot.operators);
expect(latestBOset.operators).deep.equal(ballot.operators);
});

it('Should be able to vote for a same number of bridge operators', async () => {
Expand All @@ -341,7 +341,7 @@ describe('Governance Admin test', () => {
expect(lastLength).eq(ballot.operators.length);
expect(latestBOset.period).eq(ballot.period);
expect(latestBOset.epoch).eq(ballot.epoch);
expect(latestBOset.operators).eql(ballot.operators);
expect(latestBOset.operators).deep.equal(ballot.operators);
});
});
});
Expand Down Expand Up @@ -766,14 +766,14 @@ describe('Governance Admin test', () => {
proposal.chainId,
proposal.nonce
);
expect(voters).eql([
expect(voters).deep.equal([
trustedOrgs[1].governor.address,
trustedOrgs[0].governor.address,
trustedOrgs[2].governor.address,
]);
expect(supports).eql([VoteType.For, VoteType.Against, VoteType.Against]);
expect(supports).deep.equal([VoteType.For, VoteType.Against, VoteType.Against]);
const emptySignatures = [0, ethers.constants.HashZero, ethers.constants.HashZero];
expect(signatures).eql([
expect(signatures).deep.equal([
emptySignatures,
emptySignatures,
...votedSignatures.map((sig) => [sig.v, sig.r, sig.s]),
Expand Down
10 changes: 5 additions & 5 deletions test/helpers/candidate-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const expects = {
'CandidatesRevoked',
tx,
(event) => {
expect(event.args[0], 'invalid revoked candidates').eql(expectingRevokedCandidates);
expect(event.args[0], 'invalid revoked candidates').deep.equal(expectingRevokedCandidates);
},
1
);
Expand All @@ -33,10 +33,10 @@ export const expects = {
'CandidateGranted',
tx,
(event) => {
expect(event.args[0], 'invalid consensus address').eql(expectingConsensusAddr);
expect(event.args[1], 'invalid treasury address').eql(expectingTreasuryAddr);
expect(event.args[2], 'invalid admin address').eql(expectingAdmin);
expect(event.args[3], 'invalid bridge operator address').eql(expectingBridgeOperatorAddr);
expect(event.args[0], 'invalid consensus address').deep.equal(expectingConsensusAddr);
expect(event.args[1], 'invalid treasury address').deep.equal(expectingTreasuryAddr);
expect(event.args[2], 'invalid admin address').deep.equal(expectingAdmin);
expect(event.args[3], 'invalid bridge operator address').deep.equal(expectingBridgeOperatorAddr);
},
1
);
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/governance-admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const expects = {
tx,
(event) => {
expect(event.args[0], 'invalid proposal hash').eq(expectingProposalHash);
expect(event.args[1], 'invalid success calls').eql(expectingSuccessCalls);
expect(event.args[2], 'invalid returned datas').eql(expectingReturnedDatas);
expect(event.args[1], 'invalid success calls').deep.equal(expectingSuccessCalls);
expect(event.args[2], 'invalid returned datas').deep.equal(expectingReturnedDatas);
},
1
);
Expand Down
18 changes: 10 additions & 8 deletions test/helpers/ronin-validator-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ export const expects = {
(event) => {
expect(event.args[0], 'invalid total distributing reward').eq(expectingTotalAmount);
if (expectingValidators) {
expect(event.args[1], 'invalid validator list').eql(expectingValidators);
expect(event.args[1], 'invalid validator list').deep.equal(expectingValidators);
}
if (expectingAmounts) {
expect(event.args[2], 'invalid amount list').eql(expectingAmounts);
expect(event.args[2], 'invalid amount list').deep.equal(expectingAmounts);
}
},
1
Expand All @@ -157,7 +157,7 @@ export const expects = {
tx,
(event) => {
expect(event.args[0], 'invalid period').eq(expectingPeriod);
expect(event.args[1], 'invalid validator set').eql(expectingValidators);
expect(event.args[1], 'invalid validator set').deep.equal(expectingValidators);
},
1
);
Expand All @@ -176,7 +176,8 @@ export const expects = {
(event) => {
!!expectingPeriod && expect(event.args[0], 'invalid period').eq(expectingPeriod);
!!expectingEpoch && expect(event.args[1], 'invalid epoch').eq(expectingEpoch);
!!expectingBlockProducers && expect(event.args[2], 'invalid block producers').eql(expectingBlockProducers);
!!expectingBlockProducers &&
expect(event.args[2], 'invalid block producers').deep.equal(expectingBlockProducers);
},
1
);
Expand All @@ -195,7 +196,8 @@ export const expects = {
(event) => {
!!expectingPeriod && expect(event.args[0], 'invalid period').eq(expectingPeriod);
!!expectingEpoch && expect(event.args[1], 'invalid epoch').eq(expectingEpoch);
!!expectingBridgeOperators && expect(event.args[2], 'invalid bridge operators').eql(expectingBridgeOperators);
!!expectingBridgeOperators &&
expect(event.args[2], 'invalid bridge operators').deep.equal(expectingBridgeOperators);
},
1
);
Expand All @@ -213,8 +215,8 @@ export const expects = {
tx,
(event) => {
expect(event.args[0], 'invalid validator').eq(expectingValidator);
expect(event.args[1], 'invalid removed reward').eql(expectingRemovedReward);
expect(event.args[2], 'invalid deprecated type').eql(expectingDeprecatedType);
expect(event.args[1], 'invalid removed reward').deep.equal(expectingRemovedReward);
expect(event.args[2], 'invalid deprecated type').deep.equal(expectingDeprecatedType);
},
1
);
Expand All @@ -231,7 +233,7 @@ export const expects = {
tx,
(event) => {
expect(event.args[0], 'invalid withdraw target').eq(expectingWithdrawnTarget);
expect(event.args[1], 'invalid withdraw amount').eql(expectingWithdrawnAmount);
expect(event.args[1], 'invalid withdraw amount').deep.equal(expectingWithdrawnAmount);
},
1
);
Expand Down
18 changes: 9 additions & 9 deletions test/helpers/staking-vesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ export const expects = {
tx,
(event) => {
if (blockNumber) {
expect(event.args[0], eventName + ': invalid block number').eql(blockNumber);
expect(event.args[0], eventName + ': invalid block number').deep.equal(blockNumber);
}
if (recipient) {
expect(event.args[1], eventName + ': invalid recipient').eql(recipient);
expect(event.args[1], eventName + ': invalid recipient').deep.equal(recipient);
}
if (blockProducerBonus) {
expect(event.args[2], eventName + ': invalid block producer bonus').eql(blockProducerBonus);
expect(event.args[2], eventName + ': invalid block producer bonus').deep.equal(blockProducerBonus);
}
if (bridgeOperatorBonus) {
expect(event.args[3], eventName + ': invalid bridge operator bonus').eql(bridgeOperatorBonus);
expect(event.args[3], eventName + ': invalid bridge operator bonus').deep.equal(bridgeOperatorBonus);
}
},
1
Expand All @@ -53,19 +53,19 @@ export const expects = {
tx,
(event) => {
if (blockNumber) {
expect(event.args[0], eventName + ': invalid block number').eql(blockNumber);
expect(event.args[0], eventName + ': invalid block number').deep.equal(blockNumber);
}
if (recipient) {
expect(event.args[1], eventName + ': invalid recipient').eql(recipient);
expect(event.args[1], eventName + ': invalid recipient').deep.equal(recipient);
}
if (blockProducerBonus) {
expect(event.args[2], eventName + ': invalid block producer bonus').eql(blockProducerBonus);
expect(event.args[2], eventName + ': invalid block producer bonus').deep.equal(blockProducerBonus);
}
if (bridgeOperatorBonus) {
expect(event.args[3], eventName + ': invalid bridge operator bonus').eql(bridgeOperatorBonus);
expect(event.args[3], eventName + ': invalid bridge operator bonus').deep.equal(bridgeOperatorBonus);
}
if (bridgeOperatorBonus) {
expect(event.args[4], eventName + ': invalid contract balance').eql(contractBalance);
expect(event.args[4], eventName + ': invalid contract balance').deep.equal(contractBalance);
}
},
1
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ export const expects = {
tx,
(event) => {
if (!!expectingPeriod) {
expect(event.args[0], 'invalid period').eql(expectingPeriod);
expect(event.args[0], 'invalid period').deep.equal(expectingPeriod);
}
if (!!expectingPoolAddressList) {
expect(event.args[1], 'invalid pool address list').eql(expectingPoolAddressList);
expect(event.args[1], 'invalid pool address list').deep.equal(expectingPoolAddressList);
}
if (!!expectingAccumulatedRpsList) {
expect(event.args[2], 'invalid accumulated rps list').eql(expectingAccumulatedRpsList);
expect(event.args[2], 'invalid accumulated rps list').deep.equal(expectingAccumulatedRpsList);
}
},
1
Expand Down
5 changes: 4 additions & 1 deletion test/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { ContractTransaction } from 'ethers';
import { BigNumber, ContractTransaction } from 'ethers';
import { Interface, LogDescription } from 'ethers/lib/utils';
import { ethers, network } from 'hardhat';
import { Address } from 'hardhat-deploy/dist/types';
Expand Down Expand Up @@ -53,3 +53,6 @@ export const compareAddrs = (firstStr: string, secondStr: string) =>

export const accessControlRevertStr = (addr: Address, role: string): string =>
`AccessControl: account ${addr.toLocaleLowerCase()} is missing role ${role}`;

export const compareBigNumbers = (firstBigNumbers: BigNumber[], secondBigNumbers: BigNumber[]) =>
expect(firstBigNumbers.map((_) => _.toHexString())).deep.equal(secondBigNumbers.map((_) => _.toHexString()));
4 changes: 2 additions & 2 deletions test/integration/ActionBridgeTracking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('[Integration] Bridge Tracking test', () => {
await roninValidatorSet.connect(coinbase).wrapUpEpoch();
});
period = await roninValidatorSet.currentPeriod();
expect(await roninValidatorSet.getBridgeOperators()).eql(candidates.map((v) => v.bridgeOperator.address));
expect(await roninValidatorSet.getBridgeOperators()).deep.equal(candidates.map((v) => v.bridgeOperator.address));
});

after(async () => {
Expand All @@ -181,7 +181,7 @@ describe('[Integration] Bridge Tracking test', () => {
expect(await bridgeTracking.bridgeContract()).eq(bridgeContract.address);
expect(await bridgeContract.bridgeTrackingContract()).eq(bridgeTracking.address);
expect(await bridgeContract.validatorContract()).eq(roninValidatorSet.address);
expect(await bridgeContract.getMainchainToken(token.address, mainchainId)).eql([0, token.address]);
expect(await bridgeContract.getMainchainToken(token.address, mainchainId)).deep.equal([0, token.address]);
expect(await roninValidatorSet.currentPeriod()).eq(period);
});

Expand Down
Loading