-
Notifications
You must be signed in to change notification settings - Fork 22
/
contract.js
111 lines (101 loc) · 3.32 KB
/
contract.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var asrt = require('assert');
var erisC = require('../index');
var MockPipe = require('./mock/mock_pipe.js');
var contractManager = erisC.newContractManager(new MockPipe());
var abi = [
{
"constant": true,
"inputs": [
{
"name": "a",
"type": "int256"
},
{
"name": "b",
"type": "int256"
}
],
"name": "add",
"outputs": [
{
"name": "sum",
"type": "int256"
}
],
"type": "function"
},
{
"inputs": [],
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "a",
"type": "int256"
},
{
"indexed": true,
"name": "b",
"type": "int256"
},
{
"indexed": true,
"name": "sum",
"type": "int256"
},
{
"indexed": false,
"name": "body",
"type": "bytes32"
}
],
"name": "Added",
"type": "event"
}
];
var newAddr = "";
var contractFactory = contractManager.newContractFactory(abi);
describe('TestContract', function () {
it("should create a contract and simulate an event fired upon calling", function (done) {
contractFactory.new({to: newAddr, data: ""}, function (error, contract) {
asrt.equal(contract.address, "9FC1ECFCAE2A554D4D1A000D0D80F748E66359E3", "Contract address wrong.");
asrt.deepEqual(contract.abi, abi, "Contract abi not matching expected.");
contract.Added.once(function(error, event){
asrt.ifError(error);
asrt.equal(event.event, "Added");
asrt.equal(event.address.slice(24), contract.address);
var sum = event.args.sum.toString();
asrt.equal(sum, "30");
done();
});
contract.add(5, 25, function (error, data) {
asrt.equal(data.toString(), '30');
});
});
});
it("should create a contract and fail due to bad input", function (done) {
contractFactory.new({to: newAddr, data: ""}, function (error, contract) {
contract.add(5, "gavofyork", function (error, data) {
asrt.equal(error.message, "new BigNumber() not a number: gavofyork", "BigNumber error not reported.");
done();
});
});
});
it("should create a contract and test input succesfully", function (done) {
contractFactory.new({to: newAddr, data: ""}, function (error, contract) {
var testVal = contract.add.testInputs(5, 77);
asrt.ok(testVal, "input test did return false on proper input");
done();
});
});
it("should create a contract and test negative for bad input", function (done) {
contractFactory.new({to: newAddr, data: ""}, function (error, contract) {
var testVal = contract.add.testInputs(5, "gavofyork");
asrt.ok(!testVal, "input test did not return false on bad input");
done();
});
});
});