Skip to content

Commit

Permalink
Switch from embark to Truffle
Browse files Browse the repository at this point in the history
  • Loading branch information
ßingen committed Apr 12, 2019
1 parent 6f7728f commit 7c9c1de
Show file tree
Hide file tree
Showing 16 changed files with 699 additions and 905 deletions.
84 changes: 0 additions & 84 deletions contracts.js

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/test/TestImports.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ import "@aragon/apps-shared-migrations/contracts/Migrations.sol";

contract TestImports {
constructor() public {
// to avoid lint error
// solium-disable-previous-line no-empty-blocks
}
}
1 change: 1 addition & 0 deletions contracts/test/mocks/StakingMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "../../Staking.sol";

contract StakingMock is Staking {
constructor(ERC20 _stakingToken) Staking(_stakingToken) public {
// solium-disable-previous-line no-empty-blocks
}

uint64 _mockBlockNumber = uint64(block.number);
Expand Down
24 changes: 0 additions & 24 deletions embark.json

This file was deleted.

23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,31 @@
"version": "0.0.1",
"description": "",
"scripts": {
"test": "embark test test_embark",
"test:truffle": "./scripts/truffleit.sh && truffle test --network rpc test_truffle/*.js",
"coverage:truffle": "find ./ -iname \"*.ipc\" -exec rm -f {} \\; ; ./node_modules/.bin/solidity-coverage",
"lint": "solium --dir ./contracts"
"compile": "truffle compile",
"lint": "solium --dir ./contracts",
"test": "TRUFFLE_TEST=true npm run ganache-cli:test",
"test:gas": "GAS_REPORTER=true npm test",
"coverage": "SOLIDITY_COVERAGE=true npm run ganache-cli:test",
"truffle:dev": "node_modules/.bin/truffle dev",
"ganache-cli:test": "./node_modules/@aragon/test-helpers/ganache-cli.sh"
},
"author": "Aragon Institution MTU <contact@aragon.one>",
"license": "(GPL-3.0-or-later OR MIT)",
"repository": "https://github.com/aragon/staking",
"devDependencies": {
"@aragon/apps-shared-migrations": "1.0.0",
"@aragon/test-helpers": "^1.0.1",
"eth-gas-reporter": "^0.1.5",
"ganache-cli": "^6.1.0",
"solc": "0.4.24",
"solidity-coverage": "0.5.11",
"solidity-sha3": "^0.4.1",
"solium": "^1.0.4",
"solium": "^1.2.3",
"truffle": "4.1.14",
"truffle-bytecode-manager": "^1.1.1",
"truffle-extract": "^1.2.1",
"truffle-hdwallet-provider": "0.0.3",
"web3-eth-abi": "1.0.0-beta.33"
"truffle-hdwallet-provider": "0.0.3"
},
"dependencies": {
"@aragon/os": "^4.0.1",
"@aragon/test-helpers": "^1.0.1",
"embark": "^4.0.0",
"embarkjs-connector-web3": "^4.0.0"
"@aragon/os": "^4.1.0"
}
}
39 changes: 0 additions & 39 deletions scripts/truffleit.sh

This file was deleted.

44 changes: 20 additions & 24 deletions test_embark/checkpointing.js → test/checkpointing.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
const { assertRevert, assertInvalidOpcode } = require('./helpers/assertThrow')
const { assertRevert, assertInvalidOpcode } = require('@aragon/test-helpers/assertThrow')
//const getBalance = require('@aragon/test-helpers/balance')(web3)

const CheckpointingMock = embark.require('Embark/contracts/CheckpointingMock')
const CheckpointingMock = artifacts.require('CheckpointingMock')

let accounts

config({}, (err, accts) => {accounts = accts})

contract('Checkpointing', () => {
contract('Checkpointing', accounts => {
let checkpointing

const generateRandomTest = size => {
Expand Down Expand Up @@ -63,31 +59,31 @@ contract('Checkpointing', () => {
]

beforeEach(async () => {
checkpointing = await CheckpointingMock.deploy().send()
checkpointing = await CheckpointingMock.new()
})

context('checkpointing supports:', () => {
tests.forEach(({ description, values, expects, size }) => {
it(description, async () => {

assert.equal(await checkpointing.methods.lastUpdated().call(), 0, 'last updated should be 0')
assert.equal(await checkpointing.lastUpdated(), 0, 'last updated should be 0')

// add values sequentially
await values.reduce(
(prev, { v, t }) => prev.then(() => checkpointing.methods.add(t, v).send())
(prev, { v, t }) => prev.then(() => checkpointing.add(t, v))
, Promise.resolve())

await expects.reduce(async (prev, { t, v }) =>
prev.then(async () =>
new Promise(async (resolve, reject) => {
assert.equal(await checkpointing.methods.get(t).call(), v, 'expected value should match checkpoint')
assert.equal(await checkpointing.get(t), v, 'expected value should match checkpoint')
resolve()
})
)
, Promise.resolve())

assert.equal(await checkpointing.methods.getHistorySize().call(), size, 'size should match')
assert.equal(await checkpointing.methods.lastUpdated().call(), values.slice(-1)[0].t, 'last updated should be correct')
assert.equal(await checkpointing.getHistorySize(), size, 'size should match')
assert.equal(await checkpointing.lastUpdated(), values.slice(-1)[0].t, 'last updated should be correct')
})
})
})
Expand All @@ -96,39 +92,39 @@ contract('Checkpointing', () => {
const time = 5
const value = 2

await checkpointing.methods.add(time, value).send()
await checkpointing.add(time, value)

return assertRevert(async () => {
await checkpointing.methods.add(time - 1, value).send()
await checkpointing.add(time - 1, value)
})
})

const UINT64_OVERFLOW = (new web3.utils.BN(2)).pow(new web3.utils.BN(64))
const UINT192_OVERFLOW = (new web3.utils.BN(2)).pow(new web3.utils.BN(192))
const UINT64_OVERFLOW = (new web3.BigNumber(2)).pow(new web3.BigNumber(64))
const UINT192_OVERFLOW = (new web3.BigNumber(2)).pow(new web3.BigNumber(192))

it('fails if set value is too high', async () => {
await checkpointing.methods.add(1, UINT192_OVERFLOW.sub(new web3.utils.BN(1)).toString()).send() // can set just below limit
await checkpointing.add(1, UINT192_OVERFLOW.sub(new web3.BigNumber(1)).toString()) // can set just below limit

return assertRevert(async () => {
await checkpointing.methods.add(2, UINT192_OVERFLOW.toString()).send()
await checkpointing.add(2, UINT192_OVERFLOW.toString())
})
})

it('fails if set time is too high', async () => {
await checkpointing.methods.add(UINT64_OVERFLOW.sub(new web3.utils.BN(1)).toString(), 1).send() // can set just below limit
await checkpointing.add(UINT64_OVERFLOW.sub(new web3.BigNumber(1)).toString(), 1) // can set just below limit

return assertRevert(async () => {
await checkpointing.methods.add(UINT64_OVERFLOW.toString(), 1).send()
await checkpointing.add(UINT64_OVERFLOW.toString(), 1)
})
})

it('fails if requested time is too high', async () => {
await checkpointing.methods.add(1, 1).send()
await checkpointing.add(1, 1)

assert.equal(await checkpointing.methods.get(UINT64_OVERFLOW.sub(new web3.utils.BN(1)).toString()).call(), 1) // can request just below limit
assert.equal(await checkpointing.get(UINT64_OVERFLOW.sub(new web3.BigNumber(1)).toString()), 1) // can request just below limit

return assertRevert(async () => {
await checkpointing.methods.get(UINT64_OVERFLOW.toString()).call()
await checkpointing.get(UINT64_OVERFLOW.toString())
})
})
})
Loading

0 comments on commit 7c9c1de

Please sign in to comment.