Skip to content

Contracts: Use test helpers#608

Merged
facuspagnuolo merged 4 commits intonextfrom
contract_helpers_test
Aug 10, 2020
Merged

Contracts: Use test helpers#608
facuspagnuolo merged 4 commits intonextfrom
contract_helpers_test

Conversation

@bingen
Copy link
Contributor

@bingen bingen commented Aug 7, 2020

@bingen bingen requested review from facuspagnuolo and sohkai August 7, 2020 09:34
@bingen bingen self-assigned this Aug 7, 2020
@auto-assign auto-assign bot requested a review from izqui August 7, 2020 09:35
@bingen bingen removed the request for review from izqui August 7, 2020 09:35
@bingen bingen force-pushed the contract_helpers_test branch from b8a13e8 to d9e0d4b Compare August 7, 2020 09:41
Copy link
Contributor

@facuspagnuolo facuspagnuolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad that we are dropping all this code! Well, actually reusing it from somewhere else haha
I think it would be nice to also update the test suite to Truffle 5 + web3 1.x, please take a look at my comments on the helpers PR :)


const APP_ID = hash('stub.aragonpm.test')
const ZERO_ADDR = '0x0000000000000000000000000000000000000000'
const EMPTY_BYTES = '0x'
Copy link
Contributor

@0xGabi 0xGabi Aug 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we can replace EMPTY_BYTES everywhere for the one exported here: https://github.com/aragon/contract-helpers/blob/master/packages/test-helpers/src/bytes.js#L1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure, but perhaps we forgot to do this? Although it is different as the one in the package is 0x00.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the tests using 0x00 as empty bytes were failing, we should change it in the helpers I think

@facuspagnuolo facuspagnuolo changed the title Use Contract helpers test Contracts: Use test helpers Aug 10, 2020
@facuspagnuolo facuspagnuolo merged commit 6ba3801 into next Aug 10, 2020
@facuspagnuolo facuspagnuolo deleted the contract_helpers_test branch August 10, 2020 16:44
Copy link
Contributor

@sohkai sohkai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌 👏 Absolutely brilliant.


const APP_ID = hash('stub.aragonpm.test')
const ZERO_ADDR = '0x0000000000000000000000000000000000000000'
const EMPTY_BYTES = '0x'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure, but perhaps we forgot to do this? Although it is different as the one in the package is 0x00.

assert.equal((await tokenMock.balanceOf(owner)).valueOf(), initialBalance - approvedAmount, 'Balance of owner should be correct')
assert.equal((await tokenMock.balanceOf(receiver)).valueOf(), approvedAmount, 'Balance of receiver should be correct')
assert.equal((await tokenMock.balanceOf(safeERC20Mock.address)).valueOf(), 0, 'Balance of mock should stay the same')
assertBn(await tokenMock.balanceOf(owner), initialBalance - approvedAmount, 'Balance of owner should be correct')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but are we able to do math on BNs like this? We don't need to use sub()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, it shouldn't work this way, let me fix it anyway

it('checks block number', async () => {
assert.equal((await timeHelpersMock.getBlockNumberExt()).toString(), (await timeHelpersMock.getBlockNumber64Ext()).toString(), "block numbers should match")
assert.equal((await timeHelpersMock.getBlockNumberExt()).toString(), (await timeHelpersMock.getBlockNumberDirect()).toString(), web3.eth.blockNumber, "block number should match with real one", "block number should match with real one")
assert.equal((await timeHelpersMock.getBlockNumberExt()).toString(), (await timeHelpersMock.getBlockNumberDirect()).toString(), web3.eth.getBlockNumber, "block number should match with real one", "block number should match with real one")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit confused with this (although it's more with the original test)—do we not need to call getBlockNumber()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original was malformed, let me change it

assert.equal(
await web3.eth.getStorageAt(appStorage.address, (await appStorage.getKernelPosition())),
kernel.address,
kernel.address.toLowerCase(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm starting to wonder if we should have some sort of assertAddressEquals() or etc. so we don't have to do this 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha this one was a bit particular

@facuspagnuolo
Copy link
Contributor

Thanks for the review @sohkai, addressed your comments here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants