@caict/bop-typescript-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +5 -0
  4. package/README.md +112 -0
  5. package/package.json +90 -0
  6. package/src/bop/bop-base/README.md +5 -0
  7. package/src/bop/bop-base/base.ts +366 -0
  8. package/src/bop/bop-base/index.ts +83 -0
  9. package/src/bop/bop-base/permit.ts +116 -0
  10. package/src/bop/bop-base/test/base.test.ts +867 -0
  11. package/src/bop/bop-base/test/index.test.ts +69 -0
  12. package/src/bop/bop-base/test/permit.test.ts +125 -0
  13. package/src/bop/bop-base/tsconfig.json +8 -0
  14. package/src/bop/bop-proto/README.md +2 -0
  15. package/src/bop/bop-proto/bop-ws.proto +266 -0
  16. package/src/bop/bop-proto/bop-ws.ts +4447 -0
  17. package/src/bop/bop-proto/bop.proto +898 -0
  18. package/src/bop/bop-proto/bop.ts +12890 -0
  19. package/src/bop/bop-proto/tsconfig.json +8 -0
  20. package/src/bop/bop-ws/index.ts +315 -0
  21. package/src/bop/bop-ws/sample/sample.ts +107 -0
  22. package/src/bop/bop-ws/tsconfig.json +8 -0
  23. package/src/bop/index.ts +14 -0
  24. package/src/bop-sdk/index.ts +22 -0
  25. package/src/bop-sdk/interface/abstract-service/abstract-account.ts +23 -0
  26. package/src/bop-sdk/interface/abstract-service/abstract-chain.ts +9 -0
  27. package/src/bop-sdk/interface/abstract-service/abstract-contract.ts +16 -0
  28. package/src/bop-sdk/interface/abstract-service/abstract-ledger.ts +15 -0
  29. package/src/bop-sdk/interface/abstract-service/abstract-provider.ts +13 -0
  30. package/src/bop-sdk/interface/abstract-service/abstract-signer.ts +133 -0
  31. package/src/bop-sdk/interface/abstract-service/abstract-transaction.ts +86 -0
  32. package/src/bop-sdk/interface/provider-ws.ts +10 -0
  33. package/src/bop-sdk/interface/provider.ts +22 -0
  34. package/src/bop-sdk/interface/service/3rd.ts +54 -0
  35. package/src/bop-sdk/interface/service/account.ts +86 -0
  36. package/src/bop-sdk/interface/service/chain.ts +27 -0
  37. package/src/bop-sdk/interface/service/contract.ts +51 -0
  38. package/src/bop-sdk/interface/service/helper.ts +426 -0
  39. package/src/bop-sdk/interface/service/ledger.ts +75 -0
  40. package/src/bop-sdk/interface/service/offline/check/index.js +138 -0
  41. package/src/bop-sdk/interface/service/offline/common/constant.js +6 -0
  42. package/src/bop-sdk/interface/service/offline/common/snowFlakeUtils.js +192 -0
  43. package/src/bop-sdk/interface/service/offline/common/util.js +511 -0
  44. package/src/bop-sdk/interface/service/offline/exception/customErrors.js +29 -0
  45. package/src/bop-sdk/interface/service/offline/exception/errors.js +90 -0
  46. package/src/bop-sdk/interface/service/offline/exception/index.js +5 -0
  47. package/src/bop-sdk/interface/service/offline/operation/accountCreateOperation.js +28 -0
  48. package/src/bop-sdk/interface/service/offline/operation/accountSetMetadataOperation.js +44 -0
  49. package/src/bop-sdk/interface/service/offline/operation/accountSetPrivilegeOperation.js +49 -0
  50. package/src/bop-sdk/interface/service/offline/operation/contractCreateOperation.js +43 -0
  51. package/src/bop-sdk/interface/service/offline/operation/contractInvokeOperation.js +42 -0
  52. package/src/bop-sdk/interface/service/offline/operation/contractInvokeRequestOperation.js +69 -0
  53. package/src/bop-sdk/interface/service/offline/operation/gasSendOperation.js +29 -0
  54. package/src/bop-sdk/interface/service/offline/operation/gasSendRequestOperation.js +61 -0
  55. package/src/bop-sdk/interface/service/offline/operation/index.js +20 -0
  56. package/src/bop-sdk/interface/service/offline/proto/chain_pb.js +12079 -0
  57. package/src/bop-sdk/interface/service/offline/proto/common_pb.js +2867 -0
  58. package/src/bop-sdk/interface/service/offline/transaction/index.js +988 -0
  59. package/src/bop-sdk/interface/service/offline/transaction/operations.js +188 -0
  60. package/src/bop-sdk/interface/service/offline/validate/account.js +152 -0
  61. package/src/bop-sdk/interface/service/offline/validate/contract.js +101 -0
  62. package/src/bop-sdk/interface/service/offline/validate/index.js +10 -0
  63. package/src/bop-sdk/interface/service/offline/validate/transaction.js +51 -0
  64. package/src/bop-sdk/interface/service/transaction.ts +731 -0
  65. package/src/bop-sdk/interface/signer.ts +46 -0
  66. package/src/bop-sdk/interface/test/3rd.test.ts +1571 -0
  67. package/src/bop-sdk/interface/test/account.test.ts +284 -0
  68. package/src/bop-sdk/interface/test/chain.test.ts +45 -0
  69. package/src/bop-sdk/interface/test/contract.test.ts +283 -0
  70. package/src/bop-sdk/interface/test/ledger.test.ts +166 -0
  71. package/src/bop-sdk/interface/test/provider.test.ts +407 -0
  72. package/src/bop-sdk/interface/test/signer.test.ts +105 -0
  73. package/src/bop-sdk/interface/test/transaction.test.ts +713 -0
  74. package/src/bop-sdk/proto/bop-sdk-common.proto +159 -0
  75. package/src/bop-sdk/proto/bop-sdk-common.ts +829 -0
  76. package/src/bop-sdk/proto/bop-sdk-interface.proto +581 -0
  77. package/src/bop-sdk/proto/bop-sdk-interface.ts +10839 -0
  78. package/src/bop-sdk/proto/bop-sdk-utils.proto +86 -0
  79. package/src/bop-sdk/proto/bop-sdk-utils.ts +1495 -0
  80. package/src/bop-sdk/utils/abi/abi-coder.ts +147 -0
  81. package/src/bop-sdk/utils/abi/address.ts +109 -0
  82. package/src/bop-sdk/utils/abi/bignumber.ts +403 -0
  83. package/src/bop-sdk/utils/abi/bytes.ts +565 -0
  84. package/src/bop-sdk/utils/abi/coders/abstract-coder.ts +239 -0
  85. package/src/bop-sdk/utils/abi/coders/address.ts +58 -0
  86. package/src/bop-sdk/utils/abi/coders/anonymous.ts +25 -0
  87. package/src/bop-sdk/utils/abi/coders/array.ts +275 -0
  88. package/src/bop-sdk/utils/abi/coders/boolean.ts +21 -0
  89. package/src/bop-sdk/utils/abi/coders/bytes.ts +36 -0
  90. package/src/bop-sdk/utils/abi/coders/fixed-bytes.ts +35 -0
  91. package/src/bop-sdk/utils/abi/coders/null.ts +25 -0
  92. package/src/bop-sdk/utils/abi/coders/number.ts +56 -0
  93. package/src/bop-sdk/utils/abi/coders/string.ts +24 -0
  94. package/src/bop-sdk/utils/abi/coders/tuple.ts +73 -0
  95. package/src/bop-sdk/utils/abi/constants/addresses.ts +1 -0
  96. package/src/bop-sdk/utils/abi/constants/bignumbers.ts +30 -0
  97. package/src/bop-sdk/utils/abi/constants/hashes.ts +2 -0
  98. package/src/bop-sdk/utils/abi/constants/index.ts +15 -0
  99. package/src/bop-sdk/utils/abi/constants/strings.ts +2 -0
  100. package/src/bop-sdk/utils/abi/fragments.ts +1243 -0
  101. package/src/bop-sdk/utils/abi/id.ts +6 -0
  102. package/src/bop-sdk/utils/abi/index.ts +46 -0
  103. package/src/bop-sdk/utils/abi/interface.ts +921 -0
  104. package/src/bop-sdk/utils/abi/keccak256.ts +9 -0
  105. package/src/bop-sdk/utils/abi/properties.ts +172 -0
  106. package/src/bop-sdk/utils/abi/strings/bytes32.ts +40 -0
  107. package/src/bop-sdk/utils/abi/strings/idna.ts +258 -0
  108. package/src/bop-sdk/utils/abi/strings/index.ts +28 -0
  109. package/src/bop-sdk/utils/abi/strings/utf8.ts +373 -0
  110. package/src/bop-sdk/utils/encryption-address.ts +501 -0
  111. package/src/bop-sdk/utils/encryption-crypto.ts +427 -0
  112. package/src/bop-sdk/utils/encryption-mnemonics.ts +120 -0
  113. package/src/bop-sdk/utils/index.ts +27 -0
  114. package/src/bop-sdk/utils/logger.ts +480 -0
  115. package/src/index.ts +35 -0
@@ -0,0 +1,713 @@
1
+ import { TransactionByBop } from "../service/transaction";
2
+ import { expect } from "chai";
3
+ import * as sinon from "sinon";
4
+ import { BopInterface, Config } from "../../../bop/bop-base";
5
+ import {} from "../../../bop/bop-proto/bop";
6
+ import {
7
+ TransactionEnv,
8
+ GetTxPoolSizeResponse,
9
+ GetTransactionCacheResponse,
10
+ GetTransactionHistoryResponse,
11
+ SubmitTransactionParams,
12
+ SubmitTransactionResponse,
13
+ OpCreateAccountParams,
14
+ OpCreateContractParams,
15
+ OpGasSendParams,
16
+ OpContractInvokeParams,
17
+ OpSetMetadataParams,
18
+ OpSetPrivParams,
19
+ OpBatchGasSend,
20
+ OpBatchContractInvoke,
21
+ TxType,
22
+ OpGasSend,
23
+ ContractType,
24
+ OperationTypeThreshold_Type,
25
+ OffLineTxResponse,
26
+ TestTransactionRequest,
27
+ TestTransactionResponse,
28
+ TxBlob,
29
+ } from "../../proto/bop-sdk-interface";
30
+ import { SignerByBop } from "../signer";
31
+ import { ProviderByBop } from "../provider";
32
+
33
+ // 使用 Sinon 创建模拟对象
34
+ const sandbox = sinon.createSandbox();
35
+ describe("provider-transaction-test", () => {
36
+ let transaction: TransactionByBop;
37
+
38
+ let bopInterface: BopInterface;
39
+ let config: Config;
40
+
41
+ let signer: SignerByBop;
42
+ let signer2: SignerByBop;
43
+ let provider: ProviderByBop;
44
+
45
+ beforeEach(() => {
46
+ config = new Config("https://bif-mainnet.bitfactory.cn", "xxx", "xxx");
47
+ bopInterface = new BopInterface(config);
48
+ transaction = new TransactionByBop(bopInterface);
49
+
50
+ signer = new SignerByBop("your encprivate key");
51
+
52
+ signer2 = new SignerByBop("your encprivate key");
53
+ provider = new ProviderByBop(bopInterface);
54
+ });
55
+
56
+ afterEach(() => {
57
+ // 重置模拟对象
58
+ sandbox.restore();
59
+ });
60
+
61
+ describe("transaction test", () => {
62
+ it("transaction.getTxPoolSize", async () => {
63
+ let response: GetTxPoolSizeResponse;
64
+ response = await transaction.getTxPoolSize();
65
+ console.log(response);
66
+ expect(response.errorCode).to.equal(0);
67
+ expect(response.errorDesc).to.equal("ok");
68
+ });
69
+ it("transaction.getTransactionHistory none params", async () => {
70
+ let response: GetTransactionHistoryResponse;
71
+ response = await transaction.getTransactionHistory();
72
+ console.log(response);
73
+ expect(response.errorCode).to.equal(0);
74
+ expect(response.errorDesc).to.equal("ok");
75
+ expect(response.result?.totalCount).to.equal(100);
76
+ });
77
+ it("transaction.getTransactionHistory with exist hash", async () => {
78
+ let response: GetTransactionHistoryResponse;
79
+ response = await transaction.getTransactionHistory(
80
+ undefined,
81
+ undefined,
82
+ undefined,
83
+ "b5cef0860f6000cdfb4fa0d2dc95a013632032a49764ade7c1d972a493307315",
84
+ );
85
+ console.log(response);
86
+ console.log(
87
+ JSON.stringify(GetTransactionHistoryResponse.toJSON(response)),
88
+ );
89
+ expect(response.errorCode).to.equal(0);
90
+ expect(response.errorDesc).to.equal("ok");
91
+ expect(response.result?.totalCount).to.equal(1);
92
+ expect(
93
+ response.result?.transactions[0]?.transaction?.operations[0]?.log
94
+ ?.datas[0],
95
+ ).to.equal(
96
+ "080110641a286469643a6269643a65664765486467643141776d746755424b616333624771726d506f4e6841316b2a5618b1432802324f4661696c656420746f207375626d6974206c61796572322073746174652c206c617965723220736571283836323529206973206e6f7420657175616c206d617820736571283836323529202b20312e",
97
+ );
98
+ });
99
+ it("transaction.getTransactionHistory with not exist hash", async () => {
100
+ let response: GetTransactionHistoryResponse;
101
+ response = await transaction.getTransactionHistory(
102
+ undefined,
103
+ undefined,
104
+ undefined,
105
+ "xxx",
106
+ );
107
+ console.log(response);
108
+ console.log(
109
+ JSON.stringify(GetTransactionHistoryResponse.toJSON(response)),
110
+ );
111
+ expect(response.errorCode).to.equal(4);
112
+ });
113
+ it("transaction.getTransactionHistory with seq", async () => {
114
+ let response: GetTransactionHistoryResponse;
115
+ response = await transaction.getTransactionHistory(5845093);
116
+ console.log(response);
117
+ console.log(
118
+ JSON.stringify(GetTransactionHistoryResponse.toJSON(response)),
119
+ );
120
+ expect(response.errorCode).to.equal(0);
121
+ expect(response.errorDesc).to.equal("ok");
122
+ expect(response.result?.totalCount).to.equal(2);
123
+ });
124
+ it("transaction.getTransactionHistory with seq and start & limit", async () => {
125
+ let response: GetTransactionHistoryResponse;
126
+ response = await transaction.getTransactionHistory(5845093, 0, 1);
127
+ console.log(response);
128
+ console.log(
129
+ JSON.stringify(GetTransactionHistoryResponse.toJSON(response)),
130
+ );
131
+ expect(response.errorCode).to.equal(0);
132
+ expect(response.errorDesc).to.equal("ok");
133
+ expect(response.result?.totalCount).to.equal(2);
134
+ });
135
+ it("transaction.getTransactionHistory with seq and default start", async () => {
136
+ let response: GetTransactionHistoryResponse;
137
+ response = await transaction.getTransactionHistory(5845093);
138
+ console.log(response);
139
+ console.log(
140
+ JSON.stringify(GetTransactionHistoryResponse.toJSON(response)),
141
+ );
142
+ expect(response.errorCode).to.equal(0);
143
+ expect(response.errorDesc).to.equal("ok");
144
+ expect(response.result?.totalCount).to.equal(2);
145
+ });
146
+ it("transaction.getTransactionHistory with seq and hash", async () => {
147
+ let response: GetTransactionHistoryResponse;
148
+ response = await transaction.getTransactionHistory(
149
+ 5845127,
150
+ undefined,
151
+ undefined,
152
+ "7370f1759c37f09268d72019c006b6167392d21186e11b0bd098148ac8f34479",
153
+ );
154
+ console.log(response);
155
+ console.log(
156
+ JSON.stringify(GetTransactionHistoryResponse.toJSON(response)),
157
+ );
158
+ expect(response.errorCode).to.equal(0);
159
+ expect(response.errorDesc).to.equal("ok");
160
+ expect(response.result?.totalCount).to.equal(2);
161
+ });
162
+ it("transaction.getTransactionHistory with hash empty", async () => {
163
+ let response: GetTransactionHistoryResponse;
164
+ response = await transaction.getTransactionHistory(
165
+ undefined,
166
+ undefined,
167
+ undefined,
168
+ "",
169
+ );
170
+ console.log(response);
171
+ expect(response.errorCode).to.equal(0);
172
+ });
173
+ it("transaction.getTransactionHistory with hash invalid", async () => {
174
+ let response: GetTransactionHistoryResponse;
175
+ response = await transaction.getTransactionHistory(
176
+ undefined,
177
+ undefined,
178
+ undefined,
179
+ "xxx",
180
+ );
181
+ console.log(response);
182
+ expect(response.errorCode).to.equal(4);
183
+ });
184
+ it("transaction.getTransactionHistory with ledgerseq 0", async () => {
185
+ let response: GetTransactionHistoryResponse;
186
+ response = await transaction.getTransactionHistory(0);
187
+ console.log(response);
188
+ expect(response.errorCode).to.equal(4);
189
+ });
190
+ it("transaction.getTransactionHistory with ledgerseq negative", async () => {
191
+ let response: GetTransactionHistoryResponse;
192
+ response = await transaction.getTransactionHistory(-1);
193
+ console.log(response);
194
+ expect(response.errorCode).to.equal(4);
195
+ });
196
+ it("transaction.getTransactionHistory with ledgerseq more than max", async () => {
197
+ let response: GetTransactionHistoryResponse;
198
+ response = await transaction.getTransactionHistory(9999999999999);
199
+ console.log(response);
200
+ expect(response.errorCode).to.equal(4);
201
+ });
202
+ it("transaction.getTransactionHistory with start 0", async () => {
203
+ let response: GetTransactionHistoryResponse;
204
+ response = await transaction.getTransactionHistory(undefined, 0);
205
+ console.log(response);
206
+ expect(response.errorCode).to.equal(0);
207
+ });
208
+ it("transaction.getTransactionHistory with start negative", async () => {
209
+ let response: GetTransactionHistoryResponse;
210
+ response = await transaction.getTransactionHistory(undefined, -1);
211
+ console.log(response);
212
+ expect(response.errorCode).to.equal(0);
213
+ });
214
+ it("transaction.getTransactionHistory with start more than max", async () => {
215
+ let response: GetTransactionHistoryResponse;
216
+ response = await transaction.getTransactionHistory(
217
+ undefined,
218
+ 9999999999999,
219
+ );
220
+ console.log(response);
221
+ expect(response.errorCode).to.equal(0);
222
+ });
223
+ it("transaction.getTransactionHistory with limit 0", async () => {
224
+ let response: GetTransactionHistoryResponse;
225
+ response = await transaction.getTransactionHistory(
226
+ undefined,
227
+ undefined,
228
+ 0,
229
+ );
230
+ console.log(response);
231
+ expect(response.errorCode).to.equal(0);
232
+ });
233
+ it("transaction.getTransactionHistory with limit negative", async () => {
234
+ let response: GetTransactionHistoryResponse;
235
+ response = await transaction.getTransactionHistory(
236
+ undefined,
237
+ undefined,
238
+ -1,
239
+ );
240
+ console.log(response);
241
+ expect(response.errorCode).to.equal(0);
242
+ });
243
+ it("transaction.getTransactionHistory with limit more than max", async () => {
244
+ let response: GetTransactionHistoryResponse;
245
+ response = await transaction.getTransactionHistory(
246
+ undefined,
247
+ undefined,
248
+ 9999999999999,
249
+ );
250
+ console.log(response);
251
+ expect(response.errorCode).to.equal(0);
252
+ });
253
+ it("transaction.getTxPoolTransactions", async () => {
254
+ {
255
+ let request: OpGasSendParams = {
256
+ params: {
257
+ nonceType: TxType.INCREASE_NONCE,
258
+ gasPrice: 1,
259
+ feeLimit: 10000,
260
+ remarks: "test",
261
+ },
262
+ destAddress: "did:bid:ef27sVwzEMTEUwC1E1ivQmzEccsphtac7",
263
+ amount: 1,
264
+ };
265
+ let signerWithProvider = signer.connect(provider);
266
+ let response: OffLineTxResponse;
267
+ response = await transaction.buildGasSendTx(request, [
268
+ signerWithProvider,
269
+ ]);
270
+ console.log(response);
271
+ expect(response.errorCode).to.equal(0);
272
+ let subresponse: SubmitTransactionResponse;
273
+ subresponse = await transaction.submitTransaction({
274
+ items: [response.result],
275
+ });
276
+ console.log(subresponse);
277
+ }
278
+ let response: GetTransactionCacheResponse;
279
+ response = await transaction.getTxPoolTransactions(0);
280
+ console.log(JSON.stringify(response));
281
+ expect(response.errorCode).to.equal(4);
282
+ expect(response.errorDesc).to.equal(
283
+ "The object does not exist, such as not being able to query accounts, TX, blocks, etc",
284
+ );
285
+ });
286
+ it("transaction.buildAccountCreateTx", async () => {
287
+ let request: OpCreateAccountParams = {
288
+ params: {
289
+ nonceType: TxType.INCREASE_NONCE,
290
+ gasPrice: 1,
291
+ feeLimit: 1000,
292
+ remarks: "",
293
+ },
294
+ destAddress: "did:bid:ef26vF64vKMTGM2uCGERVXJNAobFTm7wY",
295
+ amount: 1,
296
+ };
297
+ console.log(request);
298
+ let signerWithProvider = signer.connect(provider);
299
+ let response: OffLineTxResponse;
300
+ response = await transaction.buildAccountCreateTx(request, [
301
+ signerWithProvider,
302
+ ]);
303
+ console.log(response);
304
+ expect(response.errorCode).to.equal(0);
305
+ let subresponse: SubmitTransactionResponse;
306
+ subresponse = await transaction.submitTransaction({
307
+ items: [response.result],
308
+ });
309
+ console.log(subresponse);
310
+ });
311
+ it("transaction.buildGasSendTx", async () => {
312
+ let request: OpGasSendParams = {
313
+ params: {
314
+ nonceType: TxType.INCREASE_NONCE,
315
+ gasPrice: 1,
316
+ feeLimit: 10000,
317
+ remarks: "test",
318
+ },
319
+ destAddress: "did:bid:ef27sVwzEMTEUwC1E1ivQmzEccsphtac7",
320
+ amount: 1,
321
+ };
322
+ let signerWithProvider = signer.connect(provider);
323
+ let response: OffLineTxResponse;
324
+ response = await transaction.buildGasSendTx(request, [
325
+ signerWithProvider,
326
+ ]);
327
+ console.log(response);
328
+ expect(response.errorCode).to.equal(0);
329
+ let subresponse: SubmitTransactionResponse;
330
+ subresponse = await transaction.submitTransaction({
331
+ items: [response.result],
332
+ });
333
+ console.log(subresponse);
334
+ });
335
+ it("transaction.buildContractCreateTx solidity", async () => {
336
+ let request: OpCreateContractParams = {
337
+ params: {
338
+ nonceType: TxType.INCREASE_NONCE,
339
+ gasPrice: 1,
340
+ feeLimit: 10000000,
341
+ remarks: "test",
342
+ },
343
+ initBalance: 1,
344
+ type: ContractType.EVM,
345
+ payload:
346
+ "608060405234801561000f575f80fd5b5061019a8061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c80632e64cec1146100385780636057361d14610056575b5f80fd5b610040610072565b60405161004d91906100d2565b60405180910390f35b610070600480360381019061006b9190610119565b61007a565b005b5f8054905090565b805f819055507f23b3e9cfb15bae93d147362e55f22b745d66a37405bece55b6bfbdb35a0fb060816040516100af91906100d2565b60405180910390a150565b5f819050919050565b6100cc816100ba565b82525050565b5f6020820190506100e55f8301846100c3565b92915050565b5f80fd5b6100f8816100ba565b8114610102575f80fd5b50565b5f81359050610113816100ef565b92915050565b5f6020828403121561012e5761012d6100eb565b5b5f61013b84828501610105565b9150509291505056fea2646970667358221220bb054df7a684290d3dceeca77407e3f5a111ba0b1ef00e88956c5e4f2f970ca664736f6c637822302e382e32312d63692e323032342e332e312b636f6d6d69742e31383065353661320053",
347
+ initInput: "",
348
+ };
349
+ console.log(request);
350
+ let signerWithProvider = signer.connect(provider);
351
+ let response: OffLineTxResponse;
352
+ response = await transaction.buildContractCreateTx(request, [
353
+ signerWithProvider,
354
+ ]);
355
+ console.log(response);
356
+ expect(response.errorCode).to.equal(0);
357
+ let subresponse: SubmitTransactionResponse;
358
+ subresponse = await transaction.submitTransaction({
359
+ items: [response.result],
360
+ });
361
+ console.log(subresponse);
362
+ });
363
+ it("transaction.buildContractCreateTx javascript", async () => {
364
+ let request: OpCreateContractParams = {
365
+ params: {
366
+ nonceType: TxType.INCREASE_NONCE,
367
+ gasPrice: 1,
368
+ feeLimit: 10000000,
369
+ remarks: "test",
370
+ },
371
+ initBalance: 1,
372
+ type: ContractType.JAVASCRIPT,
373
+ payload:
374
+ "'use strict';function init(input){return;}function main(input){let para=JSON.parse(input);if(para.do_foo){let x={'hello':'world'};}}function query(input){return input;}",
375
+ initInput: "",
376
+ };
377
+ console.log(request);
378
+ let signerWithProvider = signer.connect(provider);
379
+ let response: OffLineTxResponse;
380
+ response = await transaction.buildContractCreateTx(request, [
381
+ signerWithProvider,
382
+ ]);
383
+ console.log(response);
384
+ expect(response.errorCode).to.equal(0);
385
+ let subresponse: SubmitTransactionResponse;
386
+ subresponse = await transaction.submitTransaction({
387
+ items: [response.result],
388
+ });
389
+ console.log(subresponse);
390
+ });
391
+ it("transaction.buildContractInvokeTx solidity", async () => {
392
+ let request: OpContractInvokeParams = {
393
+ params: {
394
+ nonceType: TxType.INCREASE_NONCE,
395
+ gasPrice: 1,
396
+ feeLimit: 100000,
397
+ remarks: "test",
398
+ },
399
+ contractAddress: "did:bid:efhj9cgStGJckhLwHZefYS9Yje38NVuP",
400
+ input: '{"function":"store(uint256)","args":"1"}',
401
+ amount: 0,
402
+ };
403
+ console.log(request);
404
+ let signerWithProvider = signer.connect(provider);
405
+ let response: OffLineTxResponse;
406
+ response = await transaction.buildContractInvokeTx(request, [
407
+ signerWithProvider,
408
+ ]);
409
+ console.log(response);
410
+ expect(response.errorCode).to.equal(0);
411
+ let subresponse: SubmitTransactionResponse;
412
+ subresponse = await transaction.submitTransaction({
413
+ items: [response.result],
414
+ });
415
+ console.log(subresponse);
416
+ });
417
+ it("transaction.buildContractInvokeTx javascript", async () => {
418
+ let request: OpContractInvokeParams = {
419
+ params: {
420
+ nonceType: TxType.INCREASE_NONCE,
421
+ gasPrice: 1,
422
+ feeLimit: 10000,
423
+ remarks: "test",
424
+ },
425
+ contractAddress: "did:bid:eftf3aqGEQE4ANLj6U13GKqu4pzUSj2U",
426
+ input: '{"method":"getsuperlist"}',
427
+ amount: 1,
428
+ };
429
+ console.log(request);
430
+ let signerWithProvider = signer.connect(provider);
431
+ let response: OffLineTxResponse;
432
+ response = await transaction.buildContractInvokeTx(request, [
433
+ signerWithProvider,
434
+ ]);
435
+ console.log(response);
436
+ expect(response.errorCode).to.equal(0);
437
+ let subresponse: SubmitTransactionResponse;
438
+ subresponse = await transaction.submitTransaction({
439
+ items: [response.result],
440
+ });
441
+ console.log(subresponse);
442
+ });
443
+ it("transaction.buildSetMetadataTx", async () => {
444
+ let request: OpSetMetadataParams = {
445
+ params: {
446
+ nonceType: TxType.INCREASE_NONCE,
447
+ gasPrice: 1,
448
+ feeLimit: 10000,
449
+ remarks: "test",
450
+ },
451
+ key: "A",
452
+ value: "C",
453
+ version: 1,
454
+ };
455
+ console.log(request);
456
+ let signerWithProvider = signer.connect(provider);
457
+ let response: OffLineTxResponse;
458
+ response = await transaction.buildSetMetadataTx(request, [
459
+ signerWithProvider,
460
+ ]);
461
+ console.log(response);
462
+ expect(response.errorCode).to.equal(0);
463
+ let subresponse: SubmitTransactionResponse;
464
+ subresponse = await transaction.submitTransaction({
465
+ items: [response.result],
466
+ });
467
+ console.log(subresponse);
468
+ });
469
+ it("transaction.buildSetPrivilegeTx", async () => {
470
+ let request: OpSetPrivParams = {
471
+ params: {
472
+ nonceType: TxType.INCREASE_NONCE,
473
+ gasPrice: 1,
474
+ feeLimit: 10000,
475
+ remarks: "test",
476
+ },
477
+ masterWeight: "1",
478
+ signers: [
479
+ {
480
+ address: "did:bid:efsdhXX7bNYxeYYVasatAi7DPE4nM3Lb",
481
+ weight: 1,
482
+ },
483
+ ],
484
+ txThreshold: "1",
485
+ typeThresholds: [
486
+ {
487
+ type: OperationTypeThreshold_Type.CREATE_ACCOUNT,
488
+ threshold: 1,
489
+ },
490
+ ],
491
+ };
492
+ console.log(request);
493
+ let signerWithProvider = signer.connect(provider);
494
+ let response: OffLineTxResponse;
495
+ response = await transaction.buildSetPrivilegeTx(request, [
496
+ signerWithProvider,
497
+ ]);
498
+ console.log(response);
499
+ expect(response.errorCode).to.equal(0);
500
+ let subresponse: SubmitTransactionResponse;
501
+ subresponse = await transaction.submitTransaction({
502
+ items: [response.result],
503
+ });
504
+ console.log(subresponse);
505
+ });
506
+ it("transaction.buildBatchGasSend", async () => {
507
+ let request: OpBatchGasSend = {
508
+ base: {
509
+ nonceType: TxType.INCREASE_NONCE,
510
+ gasPrice: 1,
511
+ feeLimit: 10000,
512
+ remarks: "test",
513
+ },
514
+ params: [
515
+ {
516
+ destAddress: "did:bid:zfkeY37hHn2HGSeUpEdWuH76aJbkoX6H",
517
+ amount: -1,
518
+ },
519
+ {
520
+ destAddress: "did:bid:zfkeY37hHn2HGSeUpEdWuH76aJbkoX6H",
521
+ amount: 1,
522
+ },
523
+ ],
524
+ };
525
+ console.log(request);
526
+ let signerWithProvider = signer.connect(provider);
527
+ let response: OffLineTxResponse;
528
+ response = await transaction.buildBatchGasSend(request, [
529
+ signerWithProvider,
530
+ ]);
531
+ console.log(response);
532
+ expect(response.errorCode).to.equal(0);
533
+ let subresponse: SubmitTransactionResponse;
534
+ subresponse = await transaction.submitTransaction({
535
+ items: [response.result],
536
+ });
537
+ console.log(subresponse);
538
+ });
539
+ it("transaction.buildBatchContractInvoke", async () => {
540
+ let request: OpBatchContractInvoke = {
541
+ base: {
542
+ nonceType: TxType.INCREASE_NONCE,
543
+ gasPrice: 1,
544
+ feeLimit: 1000000,
545
+ remarks: "test",
546
+ },
547
+ params: [
548
+ {
549
+ contractAddress: "did:bid:efYzPhz9f3aFNAZZ42bhbLetBxPyYLdk",
550
+ input: '{"function":"store(uint256)","args":"5"}',
551
+ amount: 0,
552
+ },
553
+ {
554
+ contractAddress: "did:bid:efYzPhz9f3aFNAZZ42bhbLetBxPyYLdk",
555
+ input: '{"function":"store(uint256)","args":"6"}',
556
+ amount: 0,
557
+ },
558
+ ],
559
+ };
560
+ console.log(request);
561
+ let signerWithProvider = signer.connect(provider);
562
+ let response: OffLineTxResponse;
563
+ response = await transaction.buildBatchContractInvoke(request, [
564
+ signerWithProvider,
565
+ ]);
566
+ console.log(response);
567
+ expect(response.errorCode).to.equal(0);
568
+ let subresponse: SubmitTransactionResponse;
569
+ subresponse = await transaction.submitTransaction({
570
+ items: [response.result],
571
+ });
572
+ console.log(subresponse);
573
+ });
574
+ it("transaction.submitTransaction", async () => {
575
+ let request: OpSetMetadataParams = {
576
+ params: {
577
+ nonceType: TxType.INCREASE_NONCE,
578
+ gasPrice: 1,
579
+ feeLimit: 10000,
580
+ remarks: "test",
581
+ },
582
+ key: "A",
583
+ value: "C",
584
+ version: 2,
585
+ };
586
+ console.log(request);
587
+ let signerWithProvider = signer.connect(provider);
588
+ let response: OffLineTxResponse;
589
+ response = await transaction.buildSetMetadataTx(request, [
590
+ signerWithProvider,
591
+ ]);
592
+ console.log(JSON.stringify(response));
593
+ expect(response.errorCode).to.equal(0);
594
+ let tx: OffLineTxResponse = response;
595
+ tx.result.signatures[0].signData =
596
+ "52936dffa7ca865b592ea2d2ad5b3d0a679eb1524fdb61389018cfee0ad3b31a89dbb6ff2da9a2b228275850c2293cd20df71747a11e77769b04b090dc9d003d";
597
+ let subresponse: SubmitTransactionResponse;
598
+ subresponse = await transaction.submitTransaction({ items: [tx.result] });
599
+ console.log(subresponse);
600
+ });
601
+ it("transaction.estimateGas", async () => {
602
+ let request: TestTransactionRequest = {
603
+ items: [
604
+ {
605
+ transactionJson: {
606
+ feeLimit: 100000,
607
+ sourceAddress: "did:bid:zfVHJnop875UMPmskam4JC4kLW4tAaDK",
608
+ gasPrice: 1,
609
+ nonce: "58",
610
+ operations: [
611
+ // {
612
+ // type: 1,
613
+ // createAccount: {
614
+ // destAddress: "did:bid:ef24McYxrgR5PJUPqw8Ldhsd8XUYx1sSN",
615
+ // initBalance: 1,
616
+ // priv: {
617
+ // masterWeight: 1,
618
+ // thresholds: {
619
+ // txThreshold: 1,
620
+ // },
621
+ // },
622
+ // },
623
+ // },
624
+ // {
625
+ // type: 1,
626
+ // createAccount: {
627
+ // initBalance: 0,
628
+ // contract: {
629
+ // type: 1,
630
+ // payload: "608060405234801561000f575f80fd5b506101638061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c80632e64cec1146100385780636057361d14610056575b5f80fd5b610040610072565b60405161004d919061009b565b60405180910390f35b610070600480360381019061006b91906100e2565b61007a565b005b5f8054905090565b805f8190555050565b5f819050919050565b61009581610083565b82525050565b5f6020820190506100ae5f83018461008c565b92915050565b5f80fd5b6100c181610083565b81146100cb575f80fd5b50565b5f813590506100dc816100b8565b92915050565b5f602082840312156100f7576100f66100b4565b5b5f610104848285016100ce565b9150509291505056fea26469706673582212205e90a2a9da6608b7a94c2c5cf27906d85803927c0bd952e062893006d1814fd564736f6c637822302e382e32312d63692e323032342e332e312b636f6d6d69742e31383065353661320053"
631
+ // },
632
+ // initInput: "",
633
+ // priv: {
634
+ // masterWeight: 0,
635
+ // thresholds: {
636
+ // txThreshold: 1,
637
+ // },
638
+ // },
639
+ // },
640
+ // },
641
+ // {
642
+ // type: 1,
643
+ // createAccount: {
644
+ // initBalance: 0,
645
+ // contract: {
646
+ // type: 0,
647
+ // payload: "'use strict';function init(input){return;}function main(input){let para=JSON.parse(input);if(para.do_foo){let x={'hello':'world'};}}function query(input){return input;}"
648
+ // },
649
+ // initInput: "",
650
+ // priv: {
651
+ // masterWeight: 0,
652
+ // thresholds: {
653
+ // txThreshold: 1,
654
+ // },
655
+ // },
656
+ // },
657
+ // },
658
+ // {
659
+ // type: 7,
660
+ // payCoin: {
661
+ // destAddress: "did:bid:ef24McYxrgR5PJUPqw8Ldhsd8XUYx1sSN",
662
+ // amount: 1,
663
+ // }
664
+ // },
665
+ // {
666
+ // type: 7,
667
+ // payCoin: {
668
+ // destAddress: "did:bid:ef8eHAyVVUJeZqCpJVZGi2todhibpASp",
669
+ // amount: 0,
670
+ // input: '{"function":"store(uint256)","args":"2"}'
671
+ // }
672
+ // },
673
+ // {
674
+ // type: 7,
675
+ // payCoin: {
676
+ // destAddress: "did:bid:eftf3aqGEQE4ANLj6U13GKqu4pzUSj2U",
677
+ // amount: 0,
678
+ // input: '{"method":"getsuperlist"}'
679
+ // }
680
+ // },
681
+ // {
682
+ // type: 4,
683
+ // setMetadata: {
684
+ // key: "CCC",
685
+ // value: "C",
686
+ // version: 1,
687
+ // }
688
+ // },
689
+ // {
690
+ // type: 9,
691
+ // setPrivilege: {
692
+ // masterWeight: "1",
693
+ // typeThresholds: [
694
+ // {
695
+ // type: 1,
696
+ // threshold: 1,
697
+ // }
698
+ // ]
699
+ // }
700
+ // }
701
+ ],
702
+ },
703
+ signatureNumber: 1,
704
+ },
705
+ ],
706
+ };
707
+ let response: TestTransactionResponse;
708
+ response = await transaction.estimateGas(request);
709
+ console.log(JSON.stringify(response));
710
+ expect(response.errorCode).to.equal(0);
711
+ });
712
+ });
713
+ });