-
Notifications
You must be signed in to change notification settings - Fork 38
/
apitest.js
196 lines (165 loc) · 6.01 KB
/
apitest.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import chai from 'chai';
import chaiHttp from 'chai-http';
import chaiAsPromised from 'chai-as-promised';
import shell from 'shelljs'
import logger from "./built/utils/logger.js";
const { expect } = chai;
chai.use(chaiHttp);
chai.use(chaiAsPromised);
let res = [];
if (shell.exec('./apiactions -z Assign').code !== 0) {
shell.echo('assign failed');
shell.exit(1);
}
res[0] = await chai
.request('localhost:3000')
.post('/add')
.send({ value: 11 });
res[1] = await chai
.request('localhost:3000')
.post('/add')
.send({ value: 8 });
res[2] = await chai
.request('localhost:3000')
.post('/remove')
.send({ value: 16 });
res[3] = await chai
.request('localhost:3000')
.get('/getAllCommitments');
res[4] = await chai
.request('localhost:3000')
.get('/getCommitmentsByVariableName')
.send({ name: 'a' });
if (shell.exec('docker stop $(docker ps -q)').code !== 0) {
shell.echo('docker stop failed');
shell.exit(1);
}
if (shell.exec('docker rm apiservice').code !== 0) {
shell.echo('docker stop failed');
shell.exit(1);
}
await new Promise(resolve => setTimeout(resolve, 5000));
if (shell.exec('./apiactions -z If-Statement').code !== 0) {
shell.echo('Ifstatement failed');
shell.exit(1);
}
res[5] = await chai
.request('localhost:3000')
.post('/add')
.send({ y: 14 });
res[6] = await chai
.request('localhost:3000')
.post('/add')
.send({ y: 23 });
res[7] = await chai
.request('localhost:3000')
.get('/getAllCommitments');
res[8] = await chai
.request('localhost:3000')
.get('/getCommitmentsByVariableName')
.send({ name: 'x', mappingKey: '827641930419614124039720421795580660909102123457'});
res[9] = await chai
.request('localhost:3000')
.get('/getCommitmentsByVariableName')
.send({ name: 'z'});
if (shell.exec('docker stop $(docker ps -q)').code !== 0) {
shell.echo('docker stop failed');
shell.exit(1);
}
if (shell.exec('docker rm apiservice').code !== 0) {
shell.echo('docker stop failed');
shell.exit(1);
}
await new Promise(resolve => setTimeout(resolve, 5000));
if (shell.exec('./apiactions -z internalFunctionCallTest1').code !== 0) {
shell.echo('InternalFunctionCallTest1 failed');
shell.exit(1);
}
res[10] = await chai
.request('localhost:3000')
.post('/add')
.send({ value: 46 });
res[11] = await chai
.request('localhost:3000')
.post('/remove')
.send({ value: 33});
res[12] = await chai
.request('localhost:3000')
.get('/getAllCommitments');
res[13] = await chai
.request('localhost:3000')
.post('/add')
.send({ value: 63 });
res[14] = await chai
.request('localhost:3000')
.post('/remove')
.send({ value: 55});
res[15] = await chai
.request('localhost:3000')
.get('/getAllCommitments');
if (shell.exec('docker stop $(docker ps -q)').code !== 0) {
shell.echo('docker stop failed');
shell.exit(1);
}
if (shell.exec('docker rm apiservice').code !== 0) {
shell.echo('docker stop failed');
shell.exit(1);
}
describe('Assign Zapp', () => {
it('tests APIs are working', async () => {
expect(res[0].body.tx.event).to.equal('NewLeaves');
expect(res[1].body.tx.event).to.equal('NewLeaves');
expect(res[2].body.tx.event).to.equal('NewLeaves');
});
it('MinLeaf Index check', async () => {
expect(parseInt(res[0].body.tx.returnValues.minLeafIndex)).to.equal(0);
expect(parseInt(res[1].body.tx.returnValues.minLeafIndex)).to.equal(1);
expect(parseInt(res[2].body.tx.returnValues.minLeafIndex)).to.equal(2);
});
it('Check commitments', async () => {
expect(res[3].body.commitments.length).to.equal(3);
});
it('Check nullified commitments', async () => {
expect(res[4].body.commitments[0].isNullified).to.equal(true);
expect(res[4].body.commitments[1].isNullified).to.equal(true);
expect(res[4].body.commitments[2].isNullified).to.equal(false);
});
});
describe('If-Statement Zapp', () => {
it('tests APIs are working', async () => {
expect(res[5].body.tx.event).to.equal('NewLeaves');
expect(res[6].body.tx.event).to.equal('NewLeaves');
});
it('test MappingKey response', async () => {
expect(res[7].body.commitments.length).to.equal(2);
expect(res[7].body.commitments[0].isNullified).to.equal(true);
expect(res[7].body.commitments[1].isNullified).to.equal(false);
});
it('test stateVarId ', async () => {
expect(res[9].body.commitments[0].preimage.stateVarId).to.equal(res[9].body.commitments[1].preimage.stateVarId);
expect(res[9].body.commitments[0].isNullified).to.equal(true);
expect(res[9].body.commitments[1].isNullified).to.equal(false);
});
});
describe('InternalFunctionCallTest2 Zapp', () => {
it('tests APIs are working', async () => {
expect(res[10].body.tx.event).to.equal('NewLeaves');
expect(res[11].body.tx.event).to.equal('NewLeaves');
expect(res[13].body.tx.event).to.equal('NewLeaves');
expect(res[14].body.tx.event).to.equal('NewLeaves');
});
it('Check value after internal function call intialize', async () => {
expect(res[12].body.commitments[0].isNullified).to.equal(true);
expect(res[12].body.commitments[1].isNullified).to.equal(false);
expect(parseInt(res[12].body.commitments[0].preimage.value)).to.equal(92);
expect(parseInt(res[12].body.commitments[1].preimage.value)).to.equal(125);
});
it('Check value after internal function call after update', async () => {
expect(res[15].body.commitments[0].isNullified).to.equal(true);
expect(res[15].body.commitments[1].isNullified).to.equal(true);
expect(res[15].body.commitments[2].isNullified).to.equal(true);
expect(res[15].body.commitments[3].isNullified).to.equal(false);
expect(parseInt(res[15].body.commitments[2].preimage.value)).to.equal(251);
expect(parseInt(res[15].body.commitments[3].preimage.value)).to.equal(306);
});
});