Skip to content
Permalink
Browse files

[wip] vault: Try to increase coverage

  • Loading branch information...
bingen committed Mar 18, 2018
1 parent dfb3ad7 commit d8dac5aea23e7fe7a0170031b860d816fa0be985
Showing with 134 additions and 6 deletions.
  1. +44 −3 apps/vault/contracts/connectors/standards/ERC777.sol
  2. +0 −2 apps/vault/test/TestVault.sol
  3. +90 −1 apps/vault/test/vault.js
@@ -1,5 +1,7 @@
pragma solidity ^0.4.18;

import "@aragon/os/contracts/lib/minime/MiniMeToken.sol";
import "../../detectors/standards/ERC165.sol";

interface ERC777 {
function name() public constant returns (string);
@@ -34,8 +36,47 @@ interface ERC777TokensRecipient {
}


contract ERC777Fake {
function ERC777Fake() public {
// work around coverage weird error
contract ERC777Token is MiniMeToken, ERC165 {
function granularity() public constant returns (uint256) {
// TODO
}

function send(address to, uint256 amount) public {
// TODO
}

function send(address to, uint256 amount, bytes userData) public {
// TODO
}

function authorizeOperator(address operator) public {
// TODO
}

function revokeOperator(address operator) public {
// TODO
}

function isOperatorFor(address operator, address tokenHolder) public constant returns (bool) {
// TODO
}

function operatorSend(address from, address to, uint256 amount, bytes userData, bytes operatorData) public {
// TODO
}

function supportsInterface(bytes4 interfaceID) external view returns (bool) {
return
interfaceID == this.supportsInterface.selector || // ERC165
interfaceID == this.name.selector
^ this.symbol.selector
^ this.totalSupply.selector
^ this.granularity.selector
^ this.balanceOf.selector
// TODO! ^ this.send.selector
^ this.authorizeOperator.selector
^ this.revokeOperator.selector
^ this.isOperatorFor.selector
^ this.operatorSend.selector;
}
}
@@ -49,7 +49,6 @@ contract TestVault {
Assert.equal(address(10).balance, 1, "should hold 1 wei");
}

/*
// For some reason uncommenting this code makes truffle OOG...
function testTokenDeposit() {
token.approve(vault, 1);
@@ -58,7 +57,6 @@ contract TestVault {
Assert.equal(token.balanceOf(vault), 1, "should hold 1 token");
Assert.equal(vault.balance(token), 1, "should return 1 token balance");
}
*/

function testTransferTokens() {
address to = address(1);
@@ -1,6 +1,95 @@
const { assertRevert, assertInvalidOpcode } = require('@aragon/test-helpers/assertThrow')
const getBalance = require('@aragon/test-helpers/balance')(web3)

const Vault = artifacts.require('Vault')
const IVaultConnector = artifacts.require('IVaultConnector')

const MiniMeToken = artifacts.require('@aragon/os/contracts/lib/minime/MiniMeToken')

const getContract = name => artifacts.require(name)

const NULL_ADDRESS = '0x00'

contract('Vault app', (accounts) => {})
contract('Vault app', (accounts) => {
let vaultBase, vault, token, token777

const ETH = '0x0'
const ERC165 = 165
const NO_DETECTION = 2**32 - 1

before(async () => {
token = await MiniMeToken.new(NULL_ADDRESS, NULL_ADDRESS, 0, 'N', 0, 'N', true)
await token.generateTokens(accounts[0], 200)

token777 = await getContract('ERC777').new(NULL_ADDRESS, NULL_ADDRESS, 0, 'N', 0, 'N', true)
await token777.generateTokens(accounts[0], 200)
})

beforeEach(async () => {
vaultBase = await Vault.new()
vault = IVaultConnector.at(vaultBase.address)
await vaultBase.initializeEmpty()
await vaultBase.initializeConnectors()
//
await vaultBase
})

context('Deposits and transfers', async() => {
it('deposits ETH', async() => {
await vault.deposit(ETH, accounts[0], 1, [0], { value: 1 })
assert.equal((await getBalance(vault.address)).toString(), 1, "should hold 1 wei")
assert.equal((await vault.balance(ETH)).toString(), 1, "should return 1 wei balance")
})

it('deposits ETH trhough callback', async() => {
await vault.sendTransaction( { value: 1 })
assert.equal((await getBalance(vault.address)).toString(), 1, "should hold 1 wei")
})
})

context('Standards', async() => {
let erc20Connector, erc777Connector

before(async() => {
erc20Connector = await getContract('ERC20Connector').new()
erc777Connector = await getContract('ERC777Connector').new()
})

it('registers standard', async() => {
await vaultBase.registerStandard(777, ERC165, ["0x01", "0x02", "0x03", "0x04"], erc20Connector.address)
})

it('detects standard (no standard)', async() => {
let ts = await vaultBase.detectTokenStandard(token.address)
assert.equal(ts.toString(), 0, "standard ID should be 0")
})

it('detects standard', async() => {
let ts = await vaultBase.detectTokenStandard(token777.address)
assert.equal(ts.toString(), 0, "standard ID should be 1")
})

it('fails trying to register standard again', async() => {
return assertRevert(async() => {
await vaultBase.registerStandard(20, ERC165, ["0x01", "0x02", "0x03", "0x04"], erc20Connector.address)
})
})

it('token conforms to standard', async() => {
assert.isTrue(await vaultBase.conformsToStandard(token.address, ERC165), "should return false")
})

it('token doesn\'t conform to standard (ERC165)', async() => {
assert.isFalse(await vaultBase.conformsToStandard(token777.address, 165), "should return false")
})

it('fails checking ERC20 against ERC165', async() => {
return assertRevert(async() => {
await vaultBase.conformsToStandard(token.address, 165)
})
})
it('token doesn\'t conform to standard (not ERC165)', async() => {
assert.isFalse(await vaultBase.conformsToStandard(token.address, 0), "should return false")
})
})
})

0 comments on commit d8dac5a

Please sign in to comment.
You can’t perform that action at this time.