first truffle tests for EthereumBridge
This commit is contained in:
parent
ff3a90baf3
commit
9eadffcfdd
|
@ -9,3 +9,7 @@ trim_trailing_whitespace=true
|
|||
max_line_length=120
|
||||
insert_final_newline=true
|
||||
|
||||
[*.js]
|
||||
indent_style=space
|
||||
indent_size=2
|
||||
tab_size=2
|
||||
|
|
|
@ -15,3 +15,6 @@
|
|||
|
||||
# idea ide
|
||||
.idea
|
||||
|
||||
# truffle stuff
|
||||
truffle/build
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
pragma solidity ^0.4.16;
|
||||
pragma solidity ^0.4.15;
|
||||
|
||||
library Authorities {
|
||||
function contains (address[] self, address value) internal returns (bool) {
|
||||
|
@ -24,10 +24,10 @@ contract EthereumBridge {
|
|||
/// Number of authorities signatures required to withdraw the money.
|
||||
///
|
||||
/// Must be lesser than number of authorities.
|
||||
uint requiredSignatures;
|
||||
uint public requiredSignatures;
|
||||
|
||||
/// Contract authorities.
|
||||
address[] authorities;
|
||||
address[] public authorities;
|
||||
|
||||
/// Used kovan transaction hashes.
|
||||
mapping (bytes32 => bool) withdraws;
|
||||
|
@ -57,7 +57,8 @@ contract EthereumBridge {
|
|||
|
||||
/// Constructor.
|
||||
function EthereumBridge (uint n, address[] a) {
|
||||
require(requiredSignatures <= a.length);
|
||||
require(n != 0);
|
||||
require(n <= a.length);
|
||||
requiredSignatures = n;
|
||||
authorities = a;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
pragma solidity ^0.4.4;
|
||||
|
||||
contract Migrations {
|
||||
address public owner;
|
||||
uint public last_completed_migration;
|
||||
|
||||
modifier restricted() {
|
||||
if (msg.sender == owner) _;
|
||||
}
|
||||
|
||||
function Migrations() {
|
||||
owner = msg.sender;
|
||||
}
|
||||
|
||||
function setCompleted(uint completed) restricted {
|
||||
last_completed_migration = completed;
|
||||
}
|
||||
|
||||
function upgrade(address new_address) restricted {
|
||||
Migrations upgraded = Migrations(new_address);
|
||||
upgraded.setCompleted(last_completed_migration);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
../../contracts/bridge.sol
|
|
@ -0,0 +1,5 @@
|
|||
var Migrations = artifacts.require("./Migrations.sol");
|
||||
|
||||
module.exports = function(deployer) {
|
||||
deployer.deploy(Migrations);
|
||||
};
|
|
@ -0,0 +1,40 @@
|
|||
var EthereumBridge = artifacts.require("EthereumBridge");
|
||||
|
||||
contract('EthereumBridge', function(accounts) {
|
||||
it("should deploy contract", function() {
|
||||
var meta;
|
||||
var requiredSignatures = 1;
|
||||
var authorities = [accounts[0], accounts[1]];
|
||||
|
||||
return EthereumBridge.new(requiredSignatures, authorities).then(function(instance) {
|
||||
meta = instance;
|
||||
return meta.requiredSignatures.call();
|
||||
}).then(function(result) {
|
||||
assert.equal(requiredSignatures, result, "Contract has invalid number of requiredSignatures");
|
||||
return Promise.all(authorities.map((_, index) => meta.authorities.call(index)));
|
||||
}).then(function(result) {
|
||||
assert.deepEqual(authorities, result, "Contract has invalid authorities");
|
||||
})
|
||||
})
|
||||
|
||||
it("should create deposit event", function() {
|
||||
var meta;
|
||||
var requiredSignatures = 1;
|
||||
var authorities = [accounts[0], accounts[1]];
|
||||
let user_account = accounts[2];
|
||||
let value = web3.toWei(1, "ether");
|
||||
|
||||
return EthereumBridge.new(requiredSignatures, authorities).then(function(instance) {
|
||||
meta = instance;
|
||||
return meta.sendTransaction({
|
||||
value: value,
|
||||
from: user_account
|
||||
})
|
||||
}).then(function(result) {
|
||||
assert.equal(1, result.logs.length, "Only one event should have been created");
|
||||
assert.equal("Deposit", result.logs[0].event, "Event name should be Deposit");
|
||||
assert.equal(user_account, result.logs[0].args.recipient, "Event recipient should be transaction sender");
|
||||
assert.equal(value, result.logs[0].args.value, "Event value should match deposited ether");
|
||||
})
|
||||
})
|
||||
})
|
|
@ -0,0 +1,9 @@
|
|||
module.exports = {
|
||||
networks: {
|
||||
development: {
|
||||
host: "localhost",
|
||||
port: 8545,
|
||||
network_id: "*" // Match any network id
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue