From 84ecab801bc431a6d86369af6e6d0d85d4862844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Tanr=C4=B1kulu?= Date: Thu, 7 Dec 2023 00:37:21 +0100 Subject: [PATCH] fix test flow --- test/utils/{HexUtils.js => TestHexUtils.js} | 8 +-- test/wrapper/Constraints.behaviour.js | 17 +++-- test/wrapper/ERC1155.behaviour.js | 76 ++++++++++++--------- 3 files changed, 61 insertions(+), 40 deletions(-) rename test/utils/{HexUtils.js => TestHexUtils.js} (94%) diff --git a/test/utils/HexUtils.js b/test/utils/TestHexUtils.js similarity index 94% rename from test/utils/HexUtils.js rename to test/utils/TestHexUtils.js index 8229210d..5d39ee8e 100644 --- a/test/utils/HexUtils.js +++ b/test/utils/TestHexUtils.js @@ -45,12 +45,12 @@ describe('HexUtils', () => { }) it('Correctly parses all hex characters', async () => { let [bytes32, valid] = await HexUtils.hexStringToBytes32( - toUtf8Bytes('0123456789abcdefABCDEF'), + toUtf8Bytes('0123456789abcdefABCDEF0123456789abcdefABCD'), 0, - 22, + 40, ) expect(bytes32).to.equal( - '0x0000000000000000000000000000000000000000000123456789abcdefabcdef', + '0x0000000000000000000000000123456789abcdefabcdef0123456789abcdefab', ) expect(valid).to.equal(true) }) @@ -103,7 +103,7 @@ describe('HexUtils', () => { }) }) - describe.only('Special cases for hexStringToBytes32()', () => { + describe('Special cases for hexStringToBytes32()', () => { const hex32Bytes = '5cee339e13375638553bdf5a6e36ba80fb9f6a4f0783680884d92b558aa471da' it('odd length 1', async () => { diff --git a/test/wrapper/Constraints.behaviour.js b/test/wrapper/Constraints.behaviour.js index 91c9c13d..dc586e24 100644 --- a/test/wrapper/Constraints.behaviour.js +++ b/test/wrapper/Constraints.behaviour.js @@ -258,7 +258,10 @@ function shouldRespectConstraints(contracts, getSigners) { const parentExpiry = await BaseRegistrar.nameExpires(labelhash('test1')) await NameWrapper.setChildFuses(parentNode, childLabelHash, 0, MAX_EXPIRY) const [, , expiry] = await NameWrapper.getData(childNode) - expect(expiry).to.be.bignumber.equal(parentExpiry.add(GRACE_PERIOD)) + console.log('expiry', expiry) + expect(expiry.toString()).to.be.equal( + parentExpiry.add(GRACE_PERIOD).toString(), + ) }) it('Parent can extend expiry with setSubnodeOwner()', async () => { @@ -271,7 +274,9 @@ function shouldRespectConstraints(contracts, getSigners) { MAX_EXPIRY, ) const [, , expiry] = await NameWrapper.getData(childNode) - expect(expiry).to.be.bignumber.equal(parentExpiry.add(GRACE_PERIOD)) + expect(expiry.toString()).to.be.equal( + parentExpiry.add(GRACE_PERIOD).toString(), + ) }) it('Parent can extend expiry with setSubnodeRecord()', async () => { @@ -286,7 +291,9 @@ function shouldRespectConstraints(contracts, getSigners) { MAX_EXPIRY, ) const [, , expiry] = await NameWrapper.getData(childNode) - expect(expiry).to.be.bignumber.equal(parentExpiry.add(GRACE_PERIOD)) + expect(expiry.toString()).to.be.equal( + parentExpiry.add(GRACE_PERIOD).toString(), + ) }) } @@ -309,7 +316,9 @@ function shouldRespectConstraints(contracts, getSigners) { const parentExpiry = await BaseRegistrar.nameExpires(labelhash('test1')) await NameWrapper.setChildFuses(parentNode, childLabelHash, 0, MAX_EXPIRY) const [, , expiry] = await NameWrapper.getData(childNode) - expect(expiry).to.be.bignumber.equal(parentExpiry.add(GRACE_PERIOD)) + expect(expiry.toString()).to.be.equal( + parentExpiry.add(GRACE_PERIOD).toString(), + ) }) it('Parent cannot extend expiry with setSubnodeOwner()', async () => { diff --git a/test/wrapper/ERC1155.behaviour.js b/test/wrapper/ERC1155.behaviour.js index 77520e5e..11282d40 100644 --- a/test/wrapper/ERC1155.behaviour.js +++ b/test/wrapper/ERC1155.behaviour.js @@ -75,16 +75,22 @@ function shouldBehaveLikeERC1155( context("when accounts don't own tokens", function () { it('returns zero for given addresses', async function () { expect( - await token.balanceOf(firstTokenHolderAddress, firstTokenId), - ).to.be.bignumber.equal('0') + ( + await token.balanceOf(firstTokenHolderAddress, firstTokenId) + ).toString(), + ).to.be.equal('0') expect( - await token.balanceOf(secondTokenHolderAddress, secondTokenId), - ).to.be.bignumber.equal('0') + ( + await token.balanceOf(secondTokenHolderAddress, secondTokenId) + ).toString(), + ).to.be.equal('0') expect( - await token.balanceOf(firstTokenHolderAddress, unknownTokenId), - ).to.be.bignumber.equal('0') + ( + await token.balanceOf(firstTokenHolderAddress, unknownTokenId) + ).toString(), + ).to.be.equal('0') }) }) @@ -95,16 +101,22 @@ function shouldBehaveLikeERC1155( it('returns the amount of tokens owned by the given addresses', async function () { expect( - await token.balanceOf(firstTokenHolderAddress, firstTokenId), - ).to.be.bignumber.equal(firstAmount) + ( + await token.balanceOf(firstTokenHolderAddress, firstTokenId) + ).toString(), + ).to.be.equal(firstAmount.toString()) expect( - await token.balanceOf(secondTokenHolderAddress, secondTokenId), - ).to.be.bignumber.equal(secondAmount) + ( + await token.balanceOf(secondTokenHolderAddress, secondTokenId) + ).toString(), + ).to.be.equal(secondAmount.toString()) expect( - await token.balanceOf(firstTokenHolderAddress, unknownTokenId), - ).to.be.bignumber.equal('0') + ( + await token.balanceOf(firstTokenHolderAddress, unknownTokenId) + ).toString(), + ).to.be.equal('0') }) }) }) @@ -151,9 +163,9 @@ function shouldBehaveLikeERC1155( [firstTokenId, secondTokenId, unknownTokenId], ) expect(result).to.be.an('array') - expect(result[0]).to.be.a.bignumber.equal('0') - expect(result[1]).to.be.a.bignumber.equal('0') - expect(result[2]).to.be.a.bignumber.equal('0') + expect(result[0].toString()).to.be.equal('0') + expect(result[1].toString()).to.be.equal('0') + expect(result[2].toString()).to.be.equal('0') }) }) @@ -172,9 +184,9 @@ function shouldBehaveLikeERC1155( [secondTokenId, firstTokenId, unknownTokenId], ) expect(result).to.be.an('array') - expect(result[0]).to.be.a.bignumber.equal(secondAmount) - expect(result[1]).to.be.a.bignumber.equal(firstAmount) - expect(result[2]).to.be.a.bignumber.equal('0') + expect(result[0].toString()).to.be.equal(secondAmount.toString()) + expect(result[1].toString()).to.be.equal(firstAmount.toString()) + expect(result[2].toString()).to.be.equal('0') }) it('returns multiple times the balance of the same address when asked', async function () { @@ -187,10 +199,10 @@ function shouldBehaveLikeERC1155( [firstTokenId, secondTokenId, firstTokenId], ) expect(result).to.be.an('array') - expect(result[0]).to.be.a.bignumber.equal(result[2]) - expect(result[0]).to.be.a.bignumber.equal(firstAmount) - expect(result[1]).to.be.a.bignumber.equal(secondAmount) - expect(result[2]).to.be.a.bignumber.equal(firstAmount) + expect(result[0].toString()).to.be.equal(result[2].toString()) + expect(result[0].toString()).to.be.equal(firstAmount.toString()) + expect(result[1].toString()).to.be.equal(secondAmount.toString()) + expect(result[2].toString()).to.be.equal(firstAmount.toString()) }) }) }) @@ -275,12 +287,12 @@ function shouldBehaveLikeERC1155( it('debits transferred balance from sender', async function () { const newBalance = await token.balanceOf(from, id) - expect(newBalance).to.be.a.bignumber.equal('0') + expect(newBalance.toString()).to.be.a.equal('0') }) it('credits transferred balance to receiver', async function () { const newBalance = await token.balanceOf(this.toWhom, id) - expect(newBalance).to.be.a.bignumber.equal(value) + expect(newBalance.toString()).to.be.a.equal(value.toString()) }) it('emits a TransferSingle log', async function () { @@ -316,13 +328,13 @@ function shouldBehaveLikeERC1155( multiTokenHolderAddress, secondTokenId, ) - expect(balance1).to.be.a.bignumber.equal(secondAmount) + expect(balance1.toString()).to.be.equal(secondAmount.toString()) const balance2 = await token.balanceOf( recipientAddress, secondTokenId, ) - expect(balance2).to.be.a.bignumber.equal('0') + expect(balance2.toString()).to.be.a.bignumber.equal('0') }) }) @@ -382,13 +394,13 @@ function shouldBehaveLikeERC1155( it("preserves operator's balances not involved in the transfer", async function () { const balance1 = await token.balanceOf(proxyAddress, firstTokenId) - expect(balance1).to.be.a.bignumber.equal('0') + expect(balance1.toString()).to.be.equal('0') const balance2 = await token.balanceOf( proxyAddress, secondTokenId, ) - expect(balance2).to.be.a.bignumber.equal('0') + expect(balance2.toString()).to.be.equal('0') }) }) }, @@ -615,7 +627,7 @@ function shouldBehaveLikeERC1155( ids, ) for (const newBalance of newBalances) { - expect(newBalance).to.be.a.bignumber.equal('0') + expect(newBalance.toString()).to.be.equal('0') } }) @@ -625,7 +637,7 @@ function shouldBehaveLikeERC1155( ids, ) for (let i = 0; i < newBalances.length; i++) { - expect(newBalances[i]).to.be.a.bignumber.equal(values[i]) + expect(newBalances[i].toString()).to.be.equal(values[i].toString()) } }) @@ -714,12 +726,12 @@ function shouldBehaveLikeERC1155( it("preserves operator's balances not involved in the transfer", async function () { const balance1 = await token.balanceOf(proxyAddress, firstTokenId) - expect(balance1).to.be.a.bignumber.equal('0') + expect(balance1.toString()).to.be.equal('0') const balance2 = await token.balanceOf( proxyAddress, secondTokenId, ) - expect(balance2).to.be.a.bignumber.equal('0') + expect(balance2.toString()).to.be.equal('0') }) }) },