tests for solidity contract consturctor params

This commit is contained in:
debris 2017-09-01 15:44:36 +02:00
parent 9eadffcfdd
commit e69c9ce08d
8 changed files with 148 additions and 7 deletions

View File

@ -1 +1 @@
60606040523415600e57600080fd5b5b603680601c6000396000f30060606040525b600080fd00a165627a7a7230582082c91bbfb6935949955b38dcbd3f10609a1bb4c49fb12985828c8c70179bfca00029
60606040523415600e57600080fd5b5b603680601c6000396000f30060606040525b600080fd00a165627a7a723058205aee7bb6e405b7e171be4b11e5158482f1ad51156c48a611d60ad217bb69981c0029

View File

@ -1,4 +1,37 @@
[
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256"
}
],
"name": "authorities",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "requiredSignatures",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [

File diff suppressed because one or more lines are too long

View File

@ -44,6 +44,25 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "balances",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
@ -63,6 +82,25 @@
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256"
}
],
"name": "authorities",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
@ -81,6 +119,20 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "requiredSignatures",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [

File diff suppressed because one or more lines are too long

View File

@ -138,13 +138,13 @@ contract KovanBridge {
/// 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;
/// Ether balances
mapping (address => uint) balances;
mapping (address => uint) public balances;
/// Pending deposits and authorities who confirmed them
mapping (bytes32 => address[]) deposits;
@ -166,7 +166,8 @@ contract KovanBridge {
/// Constructor.
function KovanBridge(uint n, address[] a) {
require(requiredSignatures <= a.length);
require(n != 0);
require(n <= a.length);
requiredSignatures = n;
authorities = a;
}

View File

@ -17,6 +17,24 @@ contract('EthereumBridge', function(accounts) {
})
})
it("should fail to deploy contract with not enough required signatures", function() {
var authorities = [accounts[0], accounts[1]];
return EthereumBridge.new(0, authorities).then(function(_) {
assert(false, "Contract should fail to deploy");
}, function(err) {
// do nothing
})
})
it("should fail to deploy contract with to many signatures", function() {
var authorities = [accounts[0], accounts[1]];
return EthereumBridge.new(3, authorities).then(function(_) {
assert(false, "Contract should fail to deploy");
}, function(err) {
// do nothing
})
})
it("should create deposit event", function() {
var meta;
var requiredSignatures = 1;

37
truffle/test/testnet.js Normal file
View File

@ -0,0 +1,37 @@
var KovanBridge = artifacts.require("KovanBridge");
contract('KovanBridge', function(accounts) {
it("should deploy contract", function() {
var meta;
var requiredSignatures = 1;
var authorities = [accounts[0], accounts[1]];
return KovanBridge.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 fail to deploy contract with not enough required signatures", function() {
var authorities = [accounts[0], accounts[1]];
return KovanBridge.new(0, authorities).then(function(_) {
assert(false, "Contract should fail to deploy");
}, function(err) {
// do nothing
})
})
it("should fail to deploy contract with to many signatures", function() {
var authorities = [accounts[0], accounts[1]];
return KovanBridge.new(3, authorities).then(function(_) {
assert(false, "Contract should fail to deploy");
}, function(err) {
// do nothing
})
})
})