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

Contracts: Use test helpers #608

Merged
merged 4 commits into from
Aug 10, 2020
Merged

Contracts: Use test helpers #608

merged 4 commits into from
Aug 10, 2020

Conversation

bingen
Copy link
Contributor

@bingen bingen commented Aug 7, 2020

@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
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 :)

@@ -16,9 +14,11 @@ const ERCProxyMock = artifacts.require('ERCProxyMock')
const KernelSetAppMock = artifacts.require('KernelSetAppMock')

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.

@@ -16,9 +14,11 @@ const ERCProxyMock = artifacts.require('ERCProxyMock')
const KernelSetAppMock = artifacts.require('KernelSetAppMock')

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

@@ -7,17 +9,18 @@ contract('TimeHelpers', () => {

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

'Kernel should match'
)
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.

None yet

4 participants