Merge pull request #108 from sc-forks/transfer-test

Add transfer / send unit test. Use Node7
pull/114/head
c-g-e-w-e-k-e- 7 years ago committed by GitHub
commit 904003638d
  1. 4
      .eslintrc
  2. 2
      circle.yml
  3. 1456
      package-lock.json
  4. 2
      package.json
  5. 17
      test/app.js
  6. 23
      test/cli/wallet.js
  7. 25
      test/sources/cli/Wallet.sol

@ -3,11 +3,11 @@
"plugins": ["mocha"], "plugins": ["mocha"],
"env":{ "env":{
"meteor": true, "meteor": true,
"es6": true, "node": true,
"commonjs": true "commonjs": true
}, },
"parserOptions": { "parserOptions": {
"ecmaVersion": 6, "ecmaVersion": 2017,
"sourceType": "module" "sourceType": "module"
}, },
"rules": { "rules": {

@ -1,6 +1,6 @@
machine: machine:
node: node:
version: 6.11.0 version: 7.10.0
dependencies: dependencies:
override: override:
- rm -rf node_modules/ - rm -rf node_modules/

1456
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -23,7 +23,7 @@
"dependencies": { "dependencies": {
"commander": "^2.9.0", "commander": "^2.9.0",
"death": "^1.1.0", "death": "^1.1.0",
"ethereumjs-testrpc-sc": "4.0.1", "ethereumjs-testrpc-sc": "4.0.3",
"istanbul": "^0.4.5", "istanbul": "^0.4.5",
"keccakjs": "^0.2.1", "keccakjs": "^0.2.1",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",

@ -281,6 +281,23 @@ describe('app', () => {
collectGarbage(); collectGarbage();
}); });
it('contract sends / transfers to instrumented fallback: coverage, cleanup & exit(0)', () => {
// Validate ethereumjs-vm hack to remove gas constraints on transfer() and send()
assert(pathExists('./coverage') === false, 'should start without: coverage');
assert(pathExists('./coverage.json') === false, 'should start without: coverage.json');
mock.install('Wallet.sol', 'wallet.js', config);
shell.exec(script);
assert(shell.error() === null, 'script should not error');
assert(pathExists('./coverage') === true, 'script should gen coverage folder');
assert(pathExists('./coverage.json') === true, 'script should gen coverage.json');
const produced = JSON.parse(fs.readFileSync('./coverage.json', 'utf8'));
const path = Object.keys(produced)[0];
assert(produced[path].fnMap['1'].name === 'transferPayment', 'should map "transferPayment"');
collectGarbage();
});
it('contract uses inheritance: should generate coverage, cleanup & exit(0)', () => { it('contract uses inheritance: should generate coverage, cleanup & exit(0)', () => {
// Run against a contract that 'is' another contract // Run against a contract that 'is' another contract

@ -0,0 +1,23 @@
/* eslint-env node, mocha */
/* global artifacts, contract, assert, web3 */
const Wallet = artifacts.require('./Wallet.sol');
contract('Wallet', accounts => {
it('should should allow transfers and sends', async () => {
const walletA = await Wallet.new();
const walletB = await Wallet.new();
await walletA.sendTransaction({
value: web3.toBigNumber(100), from: accounts[0],
});
await walletA.sendPayment(50, walletB.address, {
from: accounts[0],
});
await walletA.transferPayment(50, walletB.address, {
from: accounts[0],
});
const balance = await walletB.getBalance();
assert.equal(balance.toNumber(), 100);
});
});

@ -0,0 +1,25 @@
pragma solidity ^0.4.4;
contract Wallet {
event Deposit(address indexed _sender, uint _value);
function transferPayment(uint payment, address recipient){
recipient.transfer(payment);
}
function sendPayment(uint payment, address recipient){
if (!recipient.send(payment))
revert();
}
function getBalance() constant returns(uint){
return address(this).balance;
}
function() payable
{
if (msg.value > 0)
Deposit(msg.sender, msg.value);
}
}
Loading…
Cancel
Save