/
DumbContract.spec.ts.js
374 lines (349 loc) 路 11.2 KB
/
DumbContract.spec.ts.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
exports['DumbContract should snapshot generated code 1'] = `
/* tslint:disable */
import { BigNumber } from "bignumber.js";
import * as TC from "./typechain-runtime";
export class DumbContract extends TC.TypeChainContract {
public readonly rawWeb3Contract: any;
public constructor(web3: any, address: string | BigNumber) {
const abi = [
{
constant: true,
inputs: [],
name: "arrayParamLength",
outputs: [{ name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: false,
inputs: [],
name: "countupForEther",
outputs: [],
payable: true,
stateMutability: "payable",
type: "function",
},
{
constant: true,
inputs: [],
name: "someAddress",
outputs: [{ name: "", type: "address" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: false,
inputs: [
{ name: "", type: "uint8" },
{ name: "", type: "uint8" },
{ name: "ret", type: "uint256" },
],
name: "twoUnnamedArgs",
outputs: [{ name: "", type: "uint256" }],
payable: true,
stateMutability: "payable",
type: "function",
},
{
constant: true,
inputs: [{ name: "offset", type: "int256" }],
name: "returnSigned",
outputs: [{ name: "", type: "int256" }],
payable: false,
stateMutability: "pure",
type: "function",
},
{
constant: true,
inputs: [{ name: "boolParam", type: "bool" }],
name: "callWithBoolean",
outputs: [{ name: "", type: "bool" }],
payable: false,
stateMutability: "pure",
type: "function",
},
{
constant: true,
inputs: [{ name: "arrayParam", type: "uint256[]" }],
name: "callWithArray2",
outputs: [{ name: "", type: "uint256[]" }],
payable: false,
stateMutability: "pure",
type: "function",
},
{
constant: true,
inputs: [{ name: "a", type: "address" }],
name: "testAddress",
outputs: [{ name: "", type: "address" }],
payable: false,
stateMutability: "pure",
type: "function",
},
{
constant: true,
inputs: [],
name: "counter",
outputs: [{ name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [{ name: "a", type: "string" }],
name: "testString",
outputs: [{ name: "", type: "string" }],
payable: false,
stateMutability: "pure",
type: "function",
},
{
constant: false,
inputs: [{ name: "byteParam", type: "bytes32" }],
name: "callWithBytes",
outputs: [{ name: "", type: "bytes32" }],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: true,
inputs: [{ name: "boolArrayParam", type: "bool[]" }],
name: "callWithBooleanArray",
outputs: [{ name: "", type: "bool[]" }],
payable: false,
stateMutability: "pure",
type: "function",
},
{
constant: true,
inputs: [{ name: "", type: "uint256" }],
name: "counterArray",
outputs: [{ name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: false,
inputs: [{ name: "offset", type: "uint256" }],
name: "countup",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: true,
inputs: [],
name: "returnAll",
outputs: [{ name: "", type: "uint256" }, { name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [],
name: "SOME_VALUE",
outputs: [{ name: "", type: "bool" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [{ name: "offset", type: "uint256" }],
name: "counterWithOffset",
outputs: [{ name: "sum", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [],
name: "dynamicByteArray",
outputs: [{ name: "", type: "bytes" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [],
name: "testVoidReturn",
outputs: [],
payable: false,
stateMutability: "pure",
type: "function",
},
{
constant: false,
inputs: [{ name: "dynamicBytes", type: "bytes" }],
name: "callWithDynamicByteArray",
outputs: [{ name: "", type: "bytes" }],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: true,
inputs: [],
name: "byteArray",
outputs: [{ name: "", type: "bytes32" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: false,
inputs: [{ name: "arrayParam", type: "uint256[]" }],
name: "callWithArray",
outputs: [{ name: "", type: "uint256" }],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: true,
inputs: [],
name: "returnSmallUint",
outputs: [{ name: "", type: "uint8" }],
payable: false,
stateMutability: "pure",
type: "function",
},
{
inputs: [{ name: "initialCounter", type: "uint256" }],
payable: false,
stateMutability: "nonpayable",
type: "constructor",
},
{
anonymous: false,
inputs: [
{ indexed: true, name: "from", type: "address" },
{ indexed: false, name: "value", type: "uint256" },
],
name: "Deposit",
type: "event",
},
];
super(web3, address, abi);
}
static async createAndValidate(web3: any, address: string | BigNumber): Promise<DumbContract> {
const contract = new DumbContract(web3, address);
const code = await TC.promisify(web3.eth.getCode, [address]);
// in case of missing smartcontract, code can be equal to "0x0" or "0x" depending on exact web3 implementation
// to cover all these cases we just check against the source code length 鈥斅爐here won't be any meaningful EVM program in less then 3 chars
if (code.length < 4) {
throw new Error(\`Contract at \${address} doesn't exist!\`);
}
return contract;
}
public get arrayParamLength(): Promise<BigNumber> {
return TC.promisify(this.rawWeb3Contract.arrayParamLength, []);
}
public get someAddress(): Promise<string> {
return TC.promisify(this.rawWeb3Contract.someAddress, []);
}
public get counter(): Promise<BigNumber> {
return TC.promisify(this.rawWeb3Contract.counter, []);
}
public get SOME_VALUE(): Promise<boolean> {
return TC.promisify(this.rawWeb3Contract.SOME_VALUE, []);
}
public get dynamicByteArray(): Promise<string> {
return TC.promisify(this.rawWeb3Contract.dynamicByteArray, []);
}
public get byteArray(): Promise<string> {
return TC.promisify(this.rawWeb3Contract.byteArray, []);
}
public get returnSmallUint(): Promise<BigNumber> {
return TC.promisify(this.rawWeb3Contract.returnSmallUint, []);
}
public returnSigned(offset: BigNumber | number): Promise<BigNumber> {
return TC.promisify(this.rawWeb3Contract.returnSigned, [offset.toString()]);
}
public callWithBoolean(boolParam: boolean): Promise<boolean> {
return TC.promisify(this.rawWeb3Contract.callWithBoolean, [boolParam]);
}
public callWithArray2(arrayParam: BigNumber[]): Promise<BigNumber[]> {
return TC.promisify(this.rawWeb3Contract.callWithArray2, [
arrayParam.map(arrayParamElem => arrayParamElem.toString()),
]);
}
public testAddress(a: BigNumber | string): Promise<string> {
return TC.promisify(this.rawWeb3Contract.testAddress, [a.toString()]);
}
public testString(a: string): Promise<string> {
return TC.promisify(this.rawWeb3Contract.testString, [a.toString()]);
}
public callWithBooleanArray(boolArrayParam: boolean[]): Promise<boolean[]> {
return TC.promisify(this.rawWeb3Contract.callWithBooleanArray, [
boolArrayParam.map(boolArrayParamElem => boolArrayParamElem),
]);
}
public counterArray(arg0: BigNumber | number): Promise<BigNumber> {
return TC.promisify(this.rawWeb3Contract.counterArray, [arg0.toString()]);
}
public returnAll(): Promise<[BigNumber, BigNumber]> {
return TC.promisify(this.rawWeb3Contract.returnAll, []);
}
public counterWithOffset(offset: BigNumber | number): Promise<BigNumber> {
return TC.promisify(this.rawWeb3Contract.counterWithOffset, [offset.toString()]);
}
public testVoidReturn(): Promise<void> {
return TC.promisify(this.rawWeb3Contract.testVoidReturn, []);
}
public countupForEtherTx(): TC.DeferredTransactionWrapper<TC.IPayableTxParams> {
return new TC.DeferredTransactionWrapper<TC.IPayableTxParams>(this, "countupForEther", []);
}
public twoUnnamedArgsTx(
arg0: BigNumber | number,
arg1: BigNumber | number,
ret: BigNumber | number,
): TC.DeferredTransactionWrapper<TC.IPayableTxParams> {
return new TC.DeferredTransactionWrapper<TC.IPayableTxParams>(this, "twoUnnamedArgs", [
arg0.toString(),
arg1.toString(),
ret.toString(),
]);
}
public callWithBytesTx(byteParam: string): TC.DeferredTransactionWrapper<TC.ITxParams> {
return new TC.DeferredTransactionWrapper<TC.ITxParams>(this, "callWithBytes", [
byteParam.toString(),
]);
}
public countupTx(offset: BigNumber | number): TC.DeferredTransactionWrapper<TC.ITxParams> {
return new TC.DeferredTransactionWrapper<TC.ITxParams>(this, "countup", [offset.toString()]);
}
public callWithDynamicByteArrayTx(
dynamicBytes: string,
): TC.DeferredTransactionWrapper<TC.ITxParams> {
return new TC.DeferredTransactionWrapper<TC.ITxParams>(this, "callWithDynamicByteArray", [
dynamicBytes.toString(),
]);
}
public callWithArrayTx(arrayParam: BigNumber[]): TC.DeferredTransactionWrapper<TC.ITxParams> {
return new TC.DeferredTransactionWrapper<TC.ITxParams>(this, "callWithArray", [
arrayParam.map(arrayParamElem => arrayParamElem.toString()),
]);
}
public DepositEvent(eventFilter: {
from?: BigNumber | string | Array<BigNumber | string>;
}): TC.DeferredEventWrapper<
{ from: BigNumber | string; value: BigNumber | number },
{ from?: BigNumber | string | Array<BigNumber | string> }
> {
return new TC.DeferredEventWrapper<
{ from: BigNumber | string; value: BigNumber | number },
{ from?: BigNumber | string | Array<BigNumber | string> }
>(this, "Deposit", eventFilter);
}
}
`