@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.
- package/CHANGELOG.md +34 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +112 -0
- package/package.json +90 -0
- package/src/bop/bop-base/README.md +5 -0
- package/src/bop/bop-base/base.ts +366 -0
- package/src/bop/bop-base/index.ts +83 -0
- package/src/bop/bop-base/permit.ts +116 -0
- package/src/bop/bop-base/test/base.test.ts +867 -0
- package/src/bop/bop-base/test/index.test.ts +69 -0
- package/src/bop/bop-base/test/permit.test.ts +125 -0
- package/src/bop/bop-base/tsconfig.json +8 -0
- package/src/bop/bop-proto/README.md +2 -0
- package/src/bop/bop-proto/bop-ws.proto +266 -0
- package/src/bop/bop-proto/bop-ws.ts +4447 -0
- package/src/bop/bop-proto/bop.proto +898 -0
- package/src/bop/bop-proto/bop.ts +12890 -0
- package/src/bop/bop-proto/tsconfig.json +8 -0
- package/src/bop/bop-ws/index.ts +315 -0
- package/src/bop/bop-ws/sample/sample.ts +107 -0
- package/src/bop/bop-ws/tsconfig.json +8 -0
- package/src/bop/index.ts +14 -0
- package/src/bop-sdk/index.ts +22 -0
- package/src/bop-sdk/interface/abstract-service/abstract-account.ts +23 -0
- package/src/bop-sdk/interface/abstract-service/abstract-chain.ts +9 -0
- package/src/bop-sdk/interface/abstract-service/abstract-contract.ts +16 -0
- package/src/bop-sdk/interface/abstract-service/abstract-ledger.ts +15 -0
- package/src/bop-sdk/interface/abstract-service/abstract-provider.ts +13 -0
- package/src/bop-sdk/interface/abstract-service/abstract-signer.ts +133 -0
- package/src/bop-sdk/interface/abstract-service/abstract-transaction.ts +86 -0
- package/src/bop-sdk/interface/provider-ws.ts +10 -0
- package/src/bop-sdk/interface/provider.ts +22 -0
- package/src/bop-sdk/interface/service/3rd.ts +54 -0
- package/src/bop-sdk/interface/service/account.ts +86 -0
- package/src/bop-sdk/interface/service/chain.ts +27 -0
- package/src/bop-sdk/interface/service/contract.ts +51 -0
- package/src/bop-sdk/interface/service/helper.ts +426 -0
- package/src/bop-sdk/interface/service/ledger.ts +75 -0
- package/src/bop-sdk/interface/service/offline/check/index.js +138 -0
- package/src/bop-sdk/interface/service/offline/common/constant.js +6 -0
- package/src/bop-sdk/interface/service/offline/common/snowFlakeUtils.js +192 -0
- package/src/bop-sdk/interface/service/offline/common/util.js +511 -0
- package/src/bop-sdk/interface/service/offline/exception/customErrors.js +29 -0
- package/src/bop-sdk/interface/service/offline/exception/errors.js +90 -0
- package/src/bop-sdk/interface/service/offline/exception/index.js +5 -0
- package/src/bop-sdk/interface/service/offline/operation/accountCreateOperation.js +28 -0
- package/src/bop-sdk/interface/service/offline/operation/accountSetMetadataOperation.js +44 -0
- package/src/bop-sdk/interface/service/offline/operation/accountSetPrivilegeOperation.js +49 -0
- package/src/bop-sdk/interface/service/offline/operation/contractCreateOperation.js +43 -0
- package/src/bop-sdk/interface/service/offline/operation/contractInvokeOperation.js +42 -0
- package/src/bop-sdk/interface/service/offline/operation/contractInvokeRequestOperation.js +69 -0
- package/src/bop-sdk/interface/service/offline/operation/gasSendOperation.js +29 -0
- package/src/bop-sdk/interface/service/offline/operation/gasSendRequestOperation.js +61 -0
- package/src/bop-sdk/interface/service/offline/operation/index.js +20 -0
- package/src/bop-sdk/interface/service/offline/proto/chain_pb.js +12079 -0
- package/src/bop-sdk/interface/service/offline/proto/common_pb.js +2867 -0
- package/src/bop-sdk/interface/service/offline/transaction/index.js +988 -0
- package/src/bop-sdk/interface/service/offline/transaction/operations.js +188 -0
- package/src/bop-sdk/interface/service/offline/validate/account.js +152 -0
- package/src/bop-sdk/interface/service/offline/validate/contract.js +101 -0
- package/src/bop-sdk/interface/service/offline/validate/index.js +10 -0
- package/src/bop-sdk/interface/service/offline/validate/transaction.js +51 -0
- package/src/bop-sdk/interface/service/transaction.ts +731 -0
- package/src/bop-sdk/interface/signer.ts +46 -0
- package/src/bop-sdk/interface/test/3rd.test.ts +1571 -0
- package/src/bop-sdk/interface/test/account.test.ts +284 -0
- package/src/bop-sdk/interface/test/chain.test.ts +45 -0
- package/src/bop-sdk/interface/test/contract.test.ts +283 -0
- package/src/bop-sdk/interface/test/ledger.test.ts +166 -0
- package/src/bop-sdk/interface/test/provider.test.ts +407 -0
- package/src/bop-sdk/interface/test/signer.test.ts +105 -0
- package/src/bop-sdk/interface/test/transaction.test.ts +713 -0
- package/src/bop-sdk/proto/bop-sdk-common.proto +159 -0
- package/src/bop-sdk/proto/bop-sdk-common.ts +829 -0
- package/src/bop-sdk/proto/bop-sdk-interface.proto +581 -0
- package/src/bop-sdk/proto/bop-sdk-interface.ts +10839 -0
- package/src/bop-sdk/proto/bop-sdk-utils.proto +86 -0
- package/src/bop-sdk/proto/bop-sdk-utils.ts +1495 -0
- package/src/bop-sdk/utils/abi/abi-coder.ts +147 -0
- package/src/bop-sdk/utils/abi/address.ts +109 -0
- package/src/bop-sdk/utils/abi/bignumber.ts +403 -0
- package/src/bop-sdk/utils/abi/bytes.ts +565 -0
- package/src/bop-sdk/utils/abi/coders/abstract-coder.ts +239 -0
- package/src/bop-sdk/utils/abi/coders/address.ts +58 -0
- package/src/bop-sdk/utils/abi/coders/anonymous.ts +25 -0
- package/src/bop-sdk/utils/abi/coders/array.ts +275 -0
- package/src/bop-sdk/utils/abi/coders/boolean.ts +21 -0
- package/src/bop-sdk/utils/abi/coders/bytes.ts +36 -0
- package/src/bop-sdk/utils/abi/coders/fixed-bytes.ts +35 -0
- package/src/bop-sdk/utils/abi/coders/null.ts +25 -0
- package/src/bop-sdk/utils/abi/coders/number.ts +56 -0
- package/src/bop-sdk/utils/abi/coders/string.ts +24 -0
- package/src/bop-sdk/utils/abi/coders/tuple.ts +73 -0
- package/src/bop-sdk/utils/abi/constants/addresses.ts +1 -0
- package/src/bop-sdk/utils/abi/constants/bignumbers.ts +30 -0
- package/src/bop-sdk/utils/abi/constants/hashes.ts +2 -0
- package/src/bop-sdk/utils/abi/constants/index.ts +15 -0
- package/src/bop-sdk/utils/abi/constants/strings.ts +2 -0
- package/src/bop-sdk/utils/abi/fragments.ts +1243 -0
- package/src/bop-sdk/utils/abi/id.ts +6 -0
- package/src/bop-sdk/utils/abi/index.ts +46 -0
- package/src/bop-sdk/utils/abi/interface.ts +921 -0
- package/src/bop-sdk/utils/abi/keccak256.ts +9 -0
- package/src/bop-sdk/utils/abi/properties.ts +172 -0
- package/src/bop-sdk/utils/abi/strings/bytes32.ts +40 -0
- package/src/bop-sdk/utils/abi/strings/idna.ts +258 -0
- package/src/bop-sdk/utils/abi/strings/index.ts +28 -0
- package/src/bop-sdk/utils/abi/strings/utf8.ts +373 -0
- package/src/bop-sdk/utils/encryption-address.ts +501 -0
- package/src/bop-sdk/utils/encryption-crypto.ts +427 -0
- package/src/bop-sdk/utils/encryption-mnemonics.ts +120 -0
- package/src/bop-sdk/utils/index.ts +27 -0
- package/src/bop-sdk/utils/logger.ts +480 -0
- package/src/index.ts +35 -0
|
@@ -0,0 +1,867 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { promisify } from "util";
|
|
3
|
+
import * as sinon from "sinon";
|
|
4
|
+
import { Config } from "../index";
|
|
5
|
+
import { BaseService } from "../base";
|
|
6
|
+
import {
|
|
7
|
+
HelloResponse,
|
|
8
|
+
GetAccountRequest,
|
|
9
|
+
GetAccountResponse,
|
|
10
|
+
GetAccountBaseRequest,
|
|
11
|
+
GetAccountBaseResponse,
|
|
12
|
+
GetAccountMetadataRequest,
|
|
13
|
+
GetAccountMetadataResponse,
|
|
14
|
+
GetLedgerRequest,
|
|
15
|
+
GetLedgerResponse,
|
|
16
|
+
SubmitTransactionRequest,
|
|
17
|
+
SubmitTransactionResponse,
|
|
18
|
+
GetTransactionHistoryRequest,
|
|
19
|
+
GetTransactionHistoryResponse,
|
|
20
|
+
TestTransactionRequest,
|
|
21
|
+
TestTransactionResponse,
|
|
22
|
+
CallContractRequest,
|
|
23
|
+
CallContractResponse,
|
|
24
|
+
QueryRequest,
|
|
25
|
+
QueryResponse,
|
|
26
|
+
GetTransactionCacheRequest,
|
|
27
|
+
GetTransactionCacheChainResponse,
|
|
28
|
+
GetTransactionCachePlatResponse,
|
|
29
|
+
DiscardRequest,
|
|
30
|
+
DiscardResponse,
|
|
31
|
+
GetTxCacheSizeResponse,
|
|
32
|
+
GetTransactionCachePlatResult,
|
|
33
|
+
} from "../../bop-proto/bop";
|
|
34
|
+
import { success } from "io-ts";
|
|
35
|
+
|
|
36
|
+
// 使用 Sinon 创建模拟对象
|
|
37
|
+
const sandbox = sinon.createSandbox();
|
|
38
|
+
|
|
39
|
+
describe("BaseService", () => {
|
|
40
|
+
let config: Config;
|
|
41
|
+
let baseService: BaseService;
|
|
42
|
+
let baseServiceInvalidApiKey: BaseService;
|
|
43
|
+
let baseServiceInvalidApiSecret: BaseService;
|
|
44
|
+
let baseServiceMock: sinon.SinonMock;
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
config = new Config("https://bif-mainnet.bitfactory.cn", "xxx", "xxx");
|
|
48
|
+
baseService = new BaseService(config.host, config.apiKey, config.apiSecret);
|
|
49
|
+
baseServiceInvalidApiKey = new BaseService(
|
|
50
|
+
config.host,
|
|
51
|
+
"xxxx",
|
|
52
|
+
config.apiSecret,
|
|
53
|
+
);
|
|
54
|
+
baseServiceInvalidApiSecret = new BaseService(
|
|
55
|
+
config.host,
|
|
56
|
+
config.apiKey,
|
|
57
|
+
"xxxx",
|
|
58
|
+
);
|
|
59
|
+
baseServiceMock = sandbox.mock(
|
|
60
|
+
new BaseService(config.host, config.apiKey, config.apiSecret),
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
afterEach(() => {
|
|
65
|
+
// 重置模拟对象
|
|
66
|
+
sandbox.restore();
|
|
67
|
+
});
|
|
68
|
+
describe("invalid test", () => {
|
|
69
|
+
it("invalid api-key", async () => {
|
|
70
|
+
let response: HelloResponse;
|
|
71
|
+
response = await baseServiceInvalidApiKey.hello();
|
|
72
|
+
expect(response.errorCode).to.equal(1122);
|
|
73
|
+
expect(response.errorDesc).to.equal("API Key does not exist.");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("invalid api-secret", async () => {
|
|
77
|
+
let response: HelloResponse;
|
|
78
|
+
response = await baseServiceInvalidApiSecret.hello();
|
|
79
|
+
expect(response.errorCode).to.equal(1208);
|
|
80
|
+
expect(response.errorDesc).to.equal(
|
|
81
|
+
"The provided API Secret does not match the project",
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe("api-test hello", () => {
|
|
86
|
+
//hello
|
|
87
|
+
it("normal hello", async () => {
|
|
88
|
+
let response: HelloResponse;
|
|
89
|
+
response = await baseService.hello();
|
|
90
|
+
console.log(response);
|
|
91
|
+
expect(response.errorCode).to.equal(0);
|
|
92
|
+
expect(response.errorDesc).to.equal("ok");
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
//getAccount
|
|
96
|
+
describe("api-test getAccount", () => {
|
|
97
|
+
it("getAccount only address true", async () => {
|
|
98
|
+
const request: GetAccountRequest = {
|
|
99
|
+
address: "did:bid:efEnXEGWYjHRw1CzK4KpWTdusnaRokk8",
|
|
100
|
+
};
|
|
101
|
+
let response: GetAccountResponse;
|
|
102
|
+
response = await baseService.getAccount(request);
|
|
103
|
+
expect(response.errorCode).to.equal(0);
|
|
104
|
+
expect(response.errorDesc).to.equal("ok");
|
|
105
|
+
expect(response.success).to.equal(true);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("getAccount address true with exist key", async () => {
|
|
109
|
+
const request: GetAccountRequest = {
|
|
110
|
+
address: "did:bid:efEnXEGWYjHRw1CzK4KpWTdusnaRokk8",
|
|
111
|
+
key: "layer_1_agent_did:bid:effvm1wrsYv4NHtyjvMGcPg1CWX9TW2a",
|
|
112
|
+
};
|
|
113
|
+
let response: GetAccountResponse;
|
|
114
|
+
response = await baseService.getAccount(request);
|
|
115
|
+
expect(response.errorCode).to.equal(0);
|
|
116
|
+
expect(response.errorDesc).to.equal("ok");
|
|
117
|
+
expect(response.success).to.equal(true);
|
|
118
|
+
expect(response?.result?.metadatas[0]?.key).to.equal(
|
|
119
|
+
"layer_1_agent_did:bid:effvm1wrsYv4NHtyjvMGcPg1CWX9TW2a",
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("getAccount address true with not exist key", async () => {
|
|
124
|
+
const request: GetAccountRequest = {
|
|
125
|
+
address: "did:bid:efEnXEGWYjHRw1CzK4KpWTdusnaRokk8",
|
|
126
|
+
key: "1",
|
|
127
|
+
};
|
|
128
|
+
let response: GetAccountResponse;
|
|
129
|
+
response = await baseService.getAccount(request);
|
|
130
|
+
expect(response.errorCode).to.equal(0);
|
|
131
|
+
expect(response.errorDesc).to.equal("ok");
|
|
132
|
+
expect(response.success).to.equal(true);
|
|
133
|
+
expect(response?.result?.metadatas).to.empty;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("getAccount only address and account not exist", async () => {
|
|
137
|
+
const request: GetAccountRequest = {
|
|
138
|
+
address: "did:bid:efEnXEGWYjHRw1CzK4KpWTdusnaRokk",
|
|
139
|
+
};
|
|
140
|
+
let response: GetAccountResponse;
|
|
141
|
+
response = await baseService.getAccount(request);
|
|
142
|
+
expect(response.errorCode).to.equal(4);
|
|
143
|
+
expect(response.errorDesc).to.equal(
|
|
144
|
+
"The object does not exist, such as not being able to query accounts, TX, blocks, etc",
|
|
145
|
+
);
|
|
146
|
+
expect(response.success).to.equal(false);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("getAccount only address and account invalid", async () => {
|
|
150
|
+
const request: GetAccountRequest = {
|
|
151
|
+
address: "xxx",
|
|
152
|
+
};
|
|
153
|
+
let response: GetAccountResponse;
|
|
154
|
+
response = await baseService.getAccount(request);
|
|
155
|
+
expect(response.errorCode).to.equal(4);
|
|
156
|
+
expect(response.errorDesc).to.equal(
|
|
157
|
+
"The object does not exist, such as not being able to query accounts, TX, blocks, etc",
|
|
158
|
+
);
|
|
159
|
+
expect(response.success).to.equal(false);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("getAccount address true with height(account not exist)", async () => {
|
|
163
|
+
const request: GetAccountRequest = {
|
|
164
|
+
address: "did:bid:efEnXEGWYjHRw1CzK4KpWTdusnaRokk8",
|
|
165
|
+
height: 1,
|
|
166
|
+
};
|
|
167
|
+
let response: GetAccountResponse;
|
|
168
|
+
response = await baseService.getAccount(request);
|
|
169
|
+
expect(response.errorCode).to.equal(4);
|
|
170
|
+
expect(response.errorDesc).to.equal(
|
|
171
|
+
"The object does not exist, such as not being able to query accounts, TX, blocks, etc",
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("getAccount address true with height(account exist)", async () => {
|
|
176
|
+
const request: GetAccountRequest = {
|
|
177
|
+
address: "did:bid:efEnXEGWYjHRw1CzK4KpWTdusnaRokk8",
|
|
178
|
+
height: 5000000,
|
|
179
|
+
};
|
|
180
|
+
let response: GetAccountResponse;
|
|
181
|
+
response = await baseService.getAccount(request);
|
|
182
|
+
expect(response.errorCode).to.equal(0);
|
|
183
|
+
expect(response.errorDesc).to.equal("ok");
|
|
184
|
+
expect(response.success).to.equal(true);
|
|
185
|
+
expect(response?.result?.metadatas).to.be.an("array").that.is.not.empty;
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
//getAccountBase
|
|
190
|
+
describe("api-test getAccountBase", () => {
|
|
191
|
+
it("getAccountBase address true", async () => {
|
|
192
|
+
const request: GetAccountBaseRequest = {
|
|
193
|
+
address: "did:bid:efEnXEGWYjHRw1CzK4KpWTdusnaRokk8",
|
|
194
|
+
};
|
|
195
|
+
let response: GetAccountBaseResponse;
|
|
196
|
+
response = await baseService.getAccountBase(request);
|
|
197
|
+
expect(response.errorCode).to.equal(0);
|
|
198
|
+
expect(response.errorDesc).to.equal("ok");
|
|
199
|
+
expect(response.success).to.equal(true);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("getAccountBase address with invalid address", async () => {
|
|
203
|
+
const request: GetAccountBaseRequest = {
|
|
204
|
+
address: "xxx",
|
|
205
|
+
};
|
|
206
|
+
let response: GetAccountBaseResponse;
|
|
207
|
+
response = await baseService.getAccountBase(request);
|
|
208
|
+
expect(response.errorCode).to.equal(4);
|
|
209
|
+
expect(response.errorDesc).to.equal(
|
|
210
|
+
"The object does not exist, such as not being able to query accounts, TX, blocks, etc",
|
|
211
|
+
);
|
|
212
|
+
expect(response.success).to.equal(false);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("getAccountBase address with not exist address", async () => {
|
|
216
|
+
const request: GetAccountBaseRequest = {
|
|
217
|
+
address: "did:bid:efEnXEGWYjHRw1CzK4KpWTdusnaRokk9",
|
|
218
|
+
};
|
|
219
|
+
let response: GetAccountBaseResponse;
|
|
220
|
+
response = await baseService.getAccountBase(request);
|
|
221
|
+
expect(response.errorCode).to.equal(4);
|
|
222
|
+
expect(response.errorDesc).to.equal(
|
|
223
|
+
"The object does not exist, such as not being able to query accounts, TX, blocks, etc",
|
|
224
|
+
);
|
|
225
|
+
expect(response.success).to.equal(false);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
//getAccountMetaData
|
|
230
|
+
describe("api-test getAccountMetaData", () => {
|
|
231
|
+
it("getAccountMetaData address with no key", async () => {
|
|
232
|
+
const request: GetAccountMetadataRequest = {
|
|
233
|
+
address: "did:bid:efEnXEGWYjHRw1CzK4KpWTdusnaRokk8",
|
|
234
|
+
};
|
|
235
|
+
let response: GetAccountMetadataResponse;
|
|
236
|
+
response = await baseService.getAccountMetaData(request);
|
|
237
|
+
expect(response.errorCode).to.equal(0);
|
|
238
|
+
expect(response.errorDesc).to.equal("ok");
|
|
239
|
+
expect(response.success).to.equal(true);
|
|
240
|
+
expect(Object.keys(response.result!).length).to.be.greaterThan(0);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("getAccountMetaData address with exist key", async () => {
|
|
244
|
+
const request: GetAccountMetadataRequest = {
|
|
245
|
+
address: "did:bid:efEnXEGWYjHRw1CzK4KpWTdusnaRokk8",
|
|
246
|
+
key: "layer_2_agent_did:bid:efGeHdgd1AwmtgUBKac3bGqrmPoNhA1k",
|
|
247
|
+
};
|
|
248
|
+
let response: GetAccountMetadataResponse;
|
|
249
|
+
response = await baseService.getAccountMetaData(request);
|
|
250
|
+
expect(response.errorCode).to.equal(0);
|
|
251
|
+
expect(response.errorDesc).to.equal("ok");
|
|
252
|
+
expect(response.success).to.equal(true);
|
|
253
|
+
expect(Object.keys(response.result!).length).to.be.greaterThan(0);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("getAccountMetaData address with not exist key", async () => {
|
|
257
|
+
const request: GetAccountMetadataRequest = {
|
|
258
|
+
address: "did:bid:efEnXEGWYjHRw1CzK4KpWTdusnaRokk8",
|
|
259
|
+
key: "1",
|
|
260
|
+
};
|
|
261
|
+
let response: GetAccountMetadataResponse;
|
|
262
|
+
response = await baseService.getAccountMetaData(request);
|
|
263
|
+
expect(response.errorCode).to.equal(0);
|
|
264
|
+
expect(response.errorDesc).to.equal("ok");
|
|
265
|
+
expect(response.success).to.equal(true);
|
|
266
|
+
expect(response.result).to.be.empty;
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("getAccountMetaData with invalid address", async () => {
|
|
270
|
+
const request: GetAccountMetadataRequest = {
|
|
271
|
+
address: "xxx",
|
|
272
|
+
};
|
|
273
|
+
let response: GetAccountMetadataResponse;
|
|
274
|
+
response = await baseService.getAccountMetaData(request);
|
|
275
|
+
expect(response.errorCode).to.equal(4);
|
|
276
|
+
expect(response.errorDesc).to.equal(
|
|
277
|
+
"The object does not exist, such as not being able to query accounts, TX, blocks, etc",
|
|
278
|
+
);
|
|
279
|
+
expect(response.success).to.equal(false);
|
|
280
|
+
expect(response.result).to.be.empty;
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it("getAccountMetaData with not exist address", async () => {
|
|
284
|
+
const request: GetAccountMetadataRequest = {
|
|
285
|
+
address: "did:bid:efEnXEGWYjHRw1CzK4KpWTdusnaRokk9",
|
|
286
|
+
};
|
|
287
|
+
let response: GetAccountMetadataResponse;
|
|
288
|
+
response = await baseService.getAccountMetaData(request);
|
|
289
|
+
expect(response.errorCode).to.equal(4);
|
|
290
|
+
expect(response.errorDesc).to.equal(
|
|
291
|
+
"The object does not exist, such as not being able to query accounts, TX, blocks, etc",
|
|
292
|
+
);
|
|
293
|
+
expect(response.success).to.equal(false);
|
|
294
|
+
expect(response.result).to.be.empty;
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
//getLedger
|
|
299
|
+
describe("api-test getLedger", () => {
|
|
300
|
+
it("getLedger with no params", async () => {
|
|
301
|
+
const request: GetLedgerRequest = {};
|
|
302
|
+
let response: GetLedgerResponse;
|
|
303
|
+
response = await baseService.getLedger(request);
|
|
304
|
+
expect(response.errorCode).to.equal(0);
|
|
305
|
+
expect(response.errorDesc).to.equal("ok");
|
|
306
|
+
expect(response.success).to.equal(true);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it("getLedger with normal seq", async () => {
|
|
310
|
+
const request: GetLedgerRequest = {
|
|
311
|
+
seq: 1,
|
|
312
|
+
};
|
|
313
|
+
let response: GetLedgerResponse;
|
|
314
|
+
response = await baseService.getLedger(request);
|
|
315
|
+
expect(response.errorCode).to.equal(0);
|
|
316
|
+
expect(response.errorDesc).to.equal("ok");
|
|
317
|
+
expect(response.success).to.equal(true);
|
|
318
|
+
expect(response.result?.header?.seq).to.equal(1);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("getLedger with abnormal seq", async () => {
|
|
322
|
+
const request: GetLedgerRequest = {
|
|
323
|
+
seq: 0,
|
|
324
|
+
};
|
|
325
|
+
let response: GetLedgerResponse;
|
|
326
|
+
response = await baseService.getLedger(request);
|
|
327
|
+
expect(response.errorCode).to.equal(4);
|
|
328
|
+
expect(response.errorDesc).to.equal(
|
|
329
|
+
"The object does not exist, such as not being able to query accounts, TX, blocks, etc",
|
|
330
|
+
);
|
|
331
|
+
expect(response.success).to.equal(false);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it("getLedger with leader", async () => {
|
|
335
|
+
const request: GetLedgerRequest = {
|
|
336
|
+
withLeader: true,
|
|
337
|
+
};
|
|
338
|
+
let response: GetLedgerResponse;
|
|
339
|
+
response = await baseService.getLedger(request);
|
|
340
|
+
expect(response.errorCode).to.equal(0);
|
|
341
|
+
expect(response.errorDesc).to.equal("ok");
|
|
342
|
+
expect(response.success).to.equal(true);
|
|
343
|
+
expect(response.result?.leader.length).to.be.greaterThan(0);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("getLedger with validators", async () => {
|
|
347
|
+
const request: GetLedgerRequest = {
|
|
348
|
+
withValidator: true,
|
|
349
|
+
};
|
|
350
|
+
let response: GetLedgerResponse;
|
|
351
|
+
response = await baseService.getLedger(request);
|
|
352
|
+
expect(response.errorCode).to.equal(0);
|
|
353
|
+
expect(response.errorDesc).to.equal("ok");
|
|
354
|
+
expect(response.success).to.equal(true);
|
|
355
|
+
expect(response.result?.validators.length).to.be.greaterThan(0);
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
//submitTransaction
|
|
360
|
+
describe("api-test submitTransaction", () => {
|
|
361
|
+
it("submitTransaction normal", async () => {
|
|
362
|
+
const request: SubmitTransactionRequest = {
|
|
363
|
+
items: [
|
|
364
|
+
{
|
|
365
|
+
signatures: [
|
|
366
|
+
{
|
|
367
|
+
publicKey:
|
|
368
|
+
"b065665b6fa23dc1c00b17b8d2cd86093c86bbae4c011247310f9160351bd64bc580cc",
|
|
369
|
+
signData:
|
|
370
|
+
"F62BA0BD3CC98EFBBA20DB540C6660BD4547390625AD4FF6CEB7B216985F6EFB3092E3F9E36299068D668D52CA92ABAD944D28342E0DD4D1ACEE06D700350702",
|
|
371
|
+
},
|
|
372
|
+
],
|
|
373
|
+
transactionBlob:
|
|
374
|
+
"0A286469643A6269643A6566433552456946657361427575315558624D4A577645737146526B514B6971103022D605080122D10512C305080112BE053630383036303430353233343830313536313030313035373630303038306664356235303631303133663830363130303230363030303339363030306633303036303830363034303532363030343336313036313030343135373630303033353763303130303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303930303436336666666666666666313638303633303331313533633231343631303034363537356236303030383066643562333438303135363130303532353736303030383066643562353036313030356236313030643635363562363034303531383038303630323030313832383130333832353238333831383135313831353236303230303139313530383035313930363032303031393038303833383336303030356238333831313031353631303039623537383038323031353138313834303135323630323038313031393035303631303038303536356235303530353035303930353039303831303139303630316631363830313536313030633835373830383230333830353136303031383336303230303336313031303030613033313931363831353236303230303139313530356235303932353035303530363034303531383039313033393066333562363036303630343038303531393038313031363034303532383036303062383135323630323030313766363836353663366336663230373736663732366336343030303030303030303030303030303030303030303030303030303030303030303030303030303030303831353235303930353039303536303061313635363237613761373233303538323033336431366230663863613362323334646363396233336139623533303063333630313561383838373732633761656565633965353733613537316437346338303032391A041A0208012880C2D72F2A0F63726561746520636F6E747261637430AC87E32F3864",
|
|
375
|
+
},
|
|
376
|
+
],
|
|
377
|
+
};
|
|
378
|
+
let response: SubmitTransactionResponse;
|
|
379
|
+
response = await baseService.submitTransaction(request);
|
|
380
|
+
expect(response.successCount).to.equal(1);
|
|
381
|
+
expect(response.results[0]?.hash).to.equal(
|
|
382
|
+
"d4c9eb33750d66dc471cfb276807c0f1b61ace6dd969fce9cc7ab2c49c69e40a",
|
|
383
|
+
);
|
|
384
|
+
expect(response.results[0]?.errorCode).to.equal(0);
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it("submitTransaction empty transaction", async () => {
|
|
388
|
+
const request: SubmitTransactionRequest = {
|
|
389
|
+
items: [],
|
|
390
|
+
};
|
|
391
|
+
let response: SubmitTransactionResponse;
|
|
392
|
+
response = await baseService.submitTransaction(request);
|
|
393
|
+
expect(response.successCount).to.equal(0);
|
|
394
|
+
expect(response.results[0]?.hash).to.equal("");
|
|
395
|
+
expect(response.results[0]?.errorCode).to.equal(-9);
|
|
396
|
+
expect(response.results[0]?.errorDesc).to.equal("交易数据不能为空");
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it("submitTransaction empty request", async () => {
|
|
400
|
+
const request: SubmitTransactionRequest = {};
|
|
401
|
+
let response: SubmitTransactionResponse;
|
|
402
|
+
response = await baseService.submitTransaction(request);
|
|
403
|
+
expect(response.successCount).to.equal(0);
|
|
404
|
+
expect(response.results[0]?.hash).to.equal("");
|
|
405
|
+
expect(response.results[0]?.errorCode).to.equal(-9);
|
|
406
|
+
expect(response.results[0]?.errorDesc).to.equal("交易数据不能为空");
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it("submitTransaction missing transactionBlob", async () => {
|
|
410
|
+
const request: SubmitTransactionRequest = {
|
|
411
|
+
items: [
|
|
412
|
+
{
|
|
413
|
+
signatures: [
|
|
414
|
+
{
|
|
415
|
+
publicKey:
|
|
416
|
+
"b065665b6fa23dc1c00b17b8d2cd86093c86bbae4c011247310f9160351bd64bc580cc",
|
|
417
|
+
signData:
|
|
418
|
+
"F62BA0BD3CC98EFBBA20DB540C6660BD4547390625AD4FF6CEB7B216985F6EFB3092E3F9E36299068D668D52CA92ABAD944D28342E0DD4D1ACEE06D700350702",
|
|
419
|
+
},
|
|
420
|
+
],
|
|
421
|
+
},
|
|
422
|
+
],
|
|
423
|
+
};
|
|
424
|
+
let response: SubmitTransactionResponse;
|
|
425
|
+
response = await baseService.submitTransaction(request);
|
|
426
|
+
expect(response.successCount).to.equal(0);
|
|
427
|
+
expect(response.results[0]?.hash).to.equal("");
|
|
428
|
+
expect(response.results[0]?.errorCode).to.equal(-9);
|
|
429
|
+
expect(response.results[0]?.errorDesc).to.equal(
|
|
430
|
+
"Transaction blob cannot be empty",
|
|
431
|
+
);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
it("submitTransaction missing signatures", async () => {
|
|
435
|
+
const request: SubmitTransactionRequest = {
|
|
436
|
+
items: [
|
|
437
|
+
{
|
|
438
|
+
transactionBlob:
|
|
439
|
+
"0A286469643A6269643A6566433552456946657361427575315558624D4A577645737146526B514B6971103022D605080122D10512C305080112BE053630383036303430353233343830313536313030313035373630303038306664356235303631303133663830363130303230363030303339363030306633303036303830363034303532363030343336313036313030343135373630303033353763303130303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303930303436336666666666666666313638303633303331313533633231343631303034363537356236303030383066643562333438303135363130303532353736303030383066643562353036313030356236313030643635363562363034303531383038303630323030313832383130333832353238333831383135313831353236303230303139313530383035313930363032303031393038303833383336303030356238333831313031353631303039623537383038323031353138313834303135323630323038313031393035303631303038303536356235303530353035303930353039303831303139303630316631363830313536313030633835373830383230333830353136303031383336303230303336313031303030613033313931363831353236303230303139313530356235303932353035303530363034303531383039313033393066333562363036303630343038303531393038313031363034303532383036303062383135323630323030313766363836353663366336663230373736663732366336343030303030303030303030303030303030303030303030303030303030303030303030303030303030303831353235303930353039303536303061313635363237613761373233303538323033336431366230663863613362323334646363396233336139623533303063333630313561383838373732633761656565633965353733613537316437346338303032391A041A0208012880C2D72F2A0F63726561746520636F6E747261637430AC87E32F3864",
|
|
440
|
+
},
|
|
441
|
+
],
|
|
442
|
+
};
|
|
443
|
+
let response: SubmitTransactionResponse;
|
|
444
|
+
response = await baseService.submitTransaction(request);
|
|
445
|
+
expect(response.successCount).to.equal(0);
|
|
446
|
+
expect(response.results[0]?.hash).to.equal("");
|
|
447
|
+
expect(response.results[0]?.errorCode).to.equal(-9);
|
|
448
|
+
expect(response.results[0]?.errorDesc).to.equal(
|
|
449
|
+
"Operation list cannot be empty",
|
|
450
|
+
);
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
//getTransactionHistory
|
|
454
|
+
describe("api-test getTransactionHistory", () => {
|
|
455
|
+
it("getTransactionHistory with no params", async () => {
|
|
456
|
+
const request: GetTransactionHistoryRequest = {};
|
|
457
|
+
let response: GetTransactionHistoryResponse;
|
|
458
|
+
response = await baseService.getTransactionHistory(request);
|
|
459
|
+
expect(response.errorCode).to.equal(0);
|
|
460
|
+
expect(response.errorDesc).to.equal("ok");
|
|
461
|
+
expect(response.success).to.equal(true);
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
it("getTransactionHistory with exist hash(log)", async () => {
|
|
465
|
+
const request: GetTransactionHistoryRequest = {
|
|
466
|
+
hash: "170761ce1ff9028d2855d6b0a1fd30e4324abe7847c8ff138b9aa770402c1fa8",
|
|
467
|
+
};
|
|
468
|
+
let response: GetTransactionHistoryResponse;
|
|
469
|
+
response = await baseService.getTransactionHistory(request);
|
|
470
|
+
expect(response.errorCode).to.equal(0);
|
|
471
|
+
expect(response.errorDesc).to.equal("ok");
|
|
472
|
+
expect(response.success).to.equal(true);
|
|
473
|
+
expect(response.result?.totalCount).to.equal(1);
|
|
474
|
+
expect(response.result?.transactions[0]?.hash).to.equal(
|
|
475
|
+
"170761ce1ff9028d2855d6b0a1fd30e4324abe7847c8ff138b9aa770402c1fa8",
|
|
476
|
+
);
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
it("getTransactionHistory with exist hash(pay_coin)", async () => {
|
|
480
|
+
const request: GetTransactionHistoryRequest = {
|
|
481
|
+
hash: "5b677393143a29d92e6ef5fb551e839cd0833db2a695b0f0361873576728051d",
|
|
482
|
+
};
|
|
483
|
+
let response: GetTransactionHistoryResponse;
|
|
484
|
+
response = await baseService.getTransactionHistory(request);
|
|
485
|
+
expect(response.errorCode).to.equal(0);
|
|
486
|
+
expect(response.errorDesc).to.equal("ok");
|
|
487
|
+
expect(response.success).to.equal(true);
|
|
488
|
+
expect(response.result?.totalCount).to.equal(1);
|
|
489
|
+
expect(response.result?.transactions[0]?.hash).to.equal(
|
|
490
|
+
"5b677393143a29d92e6ef5fb551e839cd0833db2a695b0f0361873576728051d",
|
|
491
|
+
);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it("getTransactionHistory with not exist hash", async () => {
|
|
495
|
+
const request: GetTransactionHistoryRequest = {
|
|
496
|
+
hash: "170761ce1ff9028d2855d6b0a1fd30e4324abe7847c8ff138b9aa770402c1fa1",
|
|
497
|
+
};
|
|
498
|
+
let response: GetTransactionHistoryResponse;
|
|
499
|
+
response = await baseService.getTransactionHistory(request);
|
|
500
|
+
expect(response.errorCode).to.equal(4);
|
|
501
|
+
expect(response.errorDesc).to.equal(
|
|
502
|
+
"The object does not exist, such as not being able to query accounts, TX, blocks, etc",
|
|
503
|
+
);
|
|
504
|
+
expect(response.success).to.equal(false);
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
it("getTransactionHistory with ledger seq", async () => {
|
|
508
|
+
const request: GetTransactionHistoryRequest = {
|
|
509
|
+
ledgerSeq: 1,
|
|
510
|
+
};
|
|
511
|
+
let response: GetTransactionHistoryResponse;
|
|
512
|
+
response = await baseService.getTransactionHistory(request);
|
|
513
|
+
expect(response.errorCode).to.equal(0);
|
|
514
|
+
expect(response.errorDesc).to.equal("ok");
|
|
515
|
+
expect(response.success).to.equal(true);
|
|
516
|
+
expect(response.result?.totalCount).to.equal(1);
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
it("getTransactionHistory with start", async () => {
|
|
520
|
+
const request: GetTransactionHistoryRequest = {
|
|
521
|
+
ledgerSeq: 5722198,
|
|
522
|
+
start: 1,
|
|
523
|
+
};
|
|
524
|
+
let response: GetTransactionHistoryResponse;
|
|
525
|
+
response = await baseService.getTransactionHistory(request);
|
|
526
|
+
expect(response.errorCode).to.equal(0);
|
|
527
|
+
expect(response.errorDesc).to.equal("ok");
|
|
528
|
+
expect(response.success).to.equal(true);
|
|
529
|
+
expect(response.result?.totalCount).to.equal(2);
|
|
530
|
+
expect(response.result?.transactions[0]?.hash).to.equal(
|
|
531
|
+
"2fcb276718da653f063f703f58ef4feac32a354de85442763e53e1a07ee7b115",
|
|
532
|
+
);
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it("getTransactionHistory with limit", async () => {
|
|
536
|
+
const request: GetTransactionHistoryRequest = {
|
|
537
|
+
ledgerSeq: 5722198,
|
|
538
|
+
limit: 1,
|
|
539
|
+
};
|
|
540
|
+
let response: GetTransactionHistoryResponse;
|
|
541
|
+
response = await baseService.getTransactionHistory(request);
|
|
542
|
+
expect(response.errorCode).to.equal(0);
|
|
543
|
+
expect(response.errorDesc).to.equal("ok");
|
|
544
|
+
expect(response.success).to.equal(true);
|
|
545
|
+
expect(response.result?.totalCount).to.equal(2);
|
|
546
|
+
expect(response.result?.transactions[0]?.hash).to.equal(
|
|
547
|
+
"7355af35bf1a841f75ef54edef160600cfbcaa3173a0024a1da8181348d54900",
|
|
548
|
+
);
|
|
549
|
+
});
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
//testTransaction
|
|
553
|
+
describe("api-test testTransaction", () => {
|
|
554
|
+
it("testTransaction ", async () => {
|
|
555
|
+
const request: TestTransactionRequest = {
|
|
556
|
+
items: [
|
|
557
|
+
{
|
|
558
|
+
transactionJson: {
|
|
559
|
+
feeLimit: 100000,
|
|
560
|
+
sourceAddress: "did:bid:efmHwsoavf2SWDkm4vwUJFwzZBWQnVV7",
|
|
561
|
+
gasPrice: 1,
|
|
562
|
+
nonce: "173",
|
|
563
|
+
operations: [
|
|
564
|
+
{
|
|
565
|
+
type: 1,
|
|
566
|
+
sourceAddress: "did:bid:efmHwsoavf2SWDkm4vwUJFwzZBWQnVV7",
|
|
567
|
+
createAccount: {
|
|
568
|
+
destAddress: "did:bid:efY72a55qY47gj2gSbvjLaLwdC439p4n",
|
|
569
|
+
initBalance: 1,
|
|
570
|
+
priv: {
|
|
571
|
+
masterWeight: 1,
|
|
572
|
+
thresholds: {
|
|
573
|
+
txThreshold: 1,
|
|
574
|
+
},
|
|
575
|
+
},
|
|
576
|
+
},
|
|
577
|
+
},
|
|
578
|
+
],
|
|
579
|
+
},
|
|
580
|
+
signatureNumber: 1,
|
|
581
|
+
},
|
|
582
|
+
],
|
|
583
|
+
};
|
|
584
|
+
let response: TestTransactionResponse;
|
|
585
|
+
response = await baseService.testTransaction(request);
|
|
586
|
+
expect(response.errorCode).to.equal(0);
|
|
587
|
+
expect(response.errorDesc).to.equal("ok");
|
|
588
|
+
expect(response.success).to.equal(true);
|
|
589
|
+
expect(response.result?.hash).to.equal(
|
|
590
|
+
"0abe44d70d64a9147d60745dff4ecd51d2dc7ede960b6018329debbe70b697a9",
|
|
591
|
+
);
|
|
592
|
+
});
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
//callContract
|
|
596
|
+
describe("api-test callContract", () => {
|
|
597
|
+
it("callContract contract address not exist", async () => {
|
|
598
|
+
const request: CallContractRequest = {
|
|
599
|
+
contractAddress: "",
|
|
600
|
+
feeLimit: 10000,
|
|
601
|
+
gasPrice: 1,
|
|
602
|
+
input: '{"method":"getsuperlist"}',
|
|
603
|
+
sourceAddress: "did:bid:ef56JqCtiFNBU7z8Y8Nd47QsNPVNbTu3",
|
|
604
|
+
};
|
|
605
|
+
let response: CallContractResponse;
|
|
606
|
+
response = await baseService.callContract(request);
|
|
607
|
+
expect(response.errorCode).to.equal(-9);
|
|
608
|
+
expect(response.errorDesc).to.equal("Contract address cannot be empty");
|
|
609
|
+
expect(response.success).to.equal(false);
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
it("callContract systemContract dpos", async () => {
|
|
613
|
+
const request: CallContractRequest = {
|
|
614
|
+
contractAddress: "did:bid:efRH1Lbsuqwc6jRw3hK4H5Hp2RhHnryS",
|
|
615
|
+
feeLimit: 10000,
|
|
616
|
+
gasPrice: 1,
|
|
617
|
+
input: '{"method":"getsuperlist"}',
|
|
618
|
+
sourceAddress: "did:bid:ef56JqCtiFNBU7z8Y8Nd47QsNPVNbTu3",
|
|
619
|
+
};
|
|
620
|
+
let response: CallContractResponse;
|
|
621
|
+
response = await baseService.callContract(request);
|
|
622
|
+
expect(response.errorCode).to.equal(0);
|
|
623
|
+
expect(response.errorDesc).to.equal("ok");
|
|
624
|
+
expect(response.success).to.equal(true);
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
it("callContract jsContract", async () => {
|
|
628
|
+
const request: CallContractRequest = {
|
|
629
|
+
contractAddress: "did:bid:ef2AAQSLB2YAuWJE8mHdUXncGWRVPkoJT",
|
|
630
|
+
feeLimit: 10000,
|
|
631
|
+
gasPrice: 1,
|
|
632
|
+
input:
|
|
633
|
+
'{"method":"queryBid", "params":"did:bid:ef2AAQSLB2YAuWJE8mHdUXncGWRVPkoJT"}',
|
|
634
|
+
sourceAddress: "did:bid:ef56JqCtiFNBU7z8Y8Nd47QsNPVNbTu3",
|
|
635
|
+
};
|
|
636
|
+
let response: CallContractResponse;
|
|
637
|
+
response = await baseService.callContract(request);
|
|
638
|
+
expect(response.result?.queryRets[0]?.error).to.equal(
|
|
639
|
+
'{"data":{"contract":"did:bid:ef2AAQSLB2YAuWJE8mHdUXncGWRVPkoJT","exception":"10706,The bid document is not existed","linenum":1}}',
|
|
640
|
+
);
|
|
641
|
+
expect(response.errorCode).to.equal(0);
|
|
642
|
+
expect(response.errorDesc).to.equal("ok");
|
|
643
|
+
expect(response.success).to.equal(true);
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
it("callContract evmContract", async () => {
|
|
647
|
+
const request: CallContractRequest = {
|
|
648
|
+
contractAddress: "did:bid:efBcAumwRYrESbpRVTo4J4vYqXXfqBzu",
|
|
649
|
+
feeLimit: 10000,
|
|
650
|
+
gasPrice: 1,
|
|
651
|
+
input:
|
|
652
|
+
'{"function":"balanceOf(address)","args":"did:bid:efBcAumwRYrESbpRVTo4J4vYqXXfqBzu","return":"returns(uint256)"',
|
|
653
|
+
sourceAddress: "did:bid:ef56JqCtiFNBU7z8Y8Nd47QsNPVNbTu3",
|
|
654
|
+
};
|
|
655
|
+
let response: CallContractResponse;
|
|
656
|
+
response = await baseService.callContract(request);
|
|
657
|
+
expect(response.result?.queryRets[0]?.result).to.equal(
|
|
658
|
+
'{"code":0,"data":"[0]","desc":"","evmcode":"0000000000000000000000000000000000000000000000000000000000000000","gasused":2767}',
|
|
659
|
+
);
|
|
660
|
+
expect(response.errorCode).to.equal(0);
|
|
661
|
+
expect(response.errorDesc).to.equal("ok");
|
|
662
|
+
expect(response.success).to.equal(true);
|
|
663
|
+
});
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
//query
|
|
667
|
+
describe("api-test query", () => {
|
|
668
|
+
it("query with no params", async () => {
|
|
669
|
+
const request: QueryRequest = {};
|
|
670
|
+
let response: QueryResponse;
|
|
671
|
+
response = await baseService.query(request);
|
|
672
|
+
expect(response.errorCode).to.equal(0);
|
|
673
|
+
expect(response.errorDesc).to.equal("ok");
|
|
674
|
+
expect(response.success).to.equal(true);
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
it("query with hash", async () => {
|
|
678
|
+
const request: QueryRequest = {
|
|
679
|
+
hash: "1b96779dab06c39c5a4d173bf0033000bd25076c7007dd03623a764ae60c9b48",
|
|
680
|
+
};
|
|
681
|
+
let response: QueryResponse;
|
|
682
|
+
response = await baseService.query(request);
|
|
683
|
+
expect(response.errorCode).to.equal(0);
|
|
684
|
+
expect(response.errorDesc).to.equal("ok");
|
|
685
|
+
expect(response.success).to.equal(true);
|
|
686
|
+
expect(response.result?.count).to.equal(1);
|
|
687
|
+
expect(response.result?.totalPage).to.equal(1);
|
|
688
|
+
expect(response.result?.transactionBases[0]?.hash).to.equal(
|
|
689
|
+
"1b96779dab06c39c5a4d173bf0033000bd25076c7007dd03623a764ae60c9b48",
|
|
690
|
+
);
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
it("query with bid and txtype", async () => {
|
|
694
|
+
const request: QueryRequest = {
|
|
695
|
+
bid: "did:bid:efU9VvMvSydLUY5h1eEPDKJSWSXKVtKG",
|
|
696
|
+
txType: 0,
|
|
697
|
+
};
|
|
698
|
+
let response: QueryResponse;
|
|
699
|
+
response = await baseService.query(request);
|
|
700
|
+
expect(response.errorCode).to.equal(0);
|
|
701
|
+
expect(response.errorDesc).to.equal("ok");
|
|
702
|
+
expect(response.success).to.equal(true);
|
|
703
|
+
expect(response.result?.count).to.equal(16);
|
|
704
|
+
expect(response.result?.totalPage).to.equal(2);
|
|
705
|
+
expect(response.result?.transactionBases[0]?.hash).to.equal(
|
|
706
|
+
"1b96779dab06c39c5a4d173bf0033000bd25076c7007dd03623a764ae60c9b48",
|
|
707
|
+
);
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
it("query with ledger_seq", async () => {
|
|
711
|
+
const request: QueryRequest = {
|
|
712
|
+
ledgerSeq: 5722974,
|
|
713
|
+
};
|
|
714
|
+
let response: QueryResponse;
|
|
715
|
+
response = await baseService.query(request);
|
|
716
|
+
expect(response.errorCode).to.equal(0);
|
|
717
|
+
expect(response.errorDesc).to.equal("ok");
|
|
718
|
+
expect(response.success).to.equal(true);
|
|
719
|
+
expect(response.result?.count).to.equal(1);
|
|
720
|
+
expect(response.result?.totalPage).to.equal(1);
|
|
721
|
+
expect(response.result?.transactionBases[0]?.hash).to.equal(
|
|
722
|
+
"1b96779dab06c39c5a4d173bf0033000bd25076c7007dd03623a764ae60c9b48",
|
|
723
|
+
);
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
it("query with start_time and end_time", async () => {
|
|
727
|
+
const request: QueryRequest = {
|
|
728
|
+
startTime: "2024-12-26 14:52:09",
|
|
729
|
+
endTime: "2024-12-26 14:52:11",
|
|
730
|
+
};
|
|
731
|
+
let response: QueryResponse;
|
|
732
|
+
response = await baseService.query(request);
|
|
733
|
+
expect(response.errorCode).to.equal(0);
|
|
734
|
+
expect(response.errorDesc).to.equal("ok");
|
|
735
|
+
expect(response.success).to.equal(true);
|
|
736
|
+
expect(response.result?.count).to.equal(1);
|
|
737
|
+
expect(response.result?.totalPage).to.equal(1);
|
|
738
|
+
expect(response.result?.transactionBases[0]?.hash).to.equal(
|
|
739
|
+
"1b96779dab06c39c5a4d173bf0033000bd25076c7007dd03623a764ae60c9b48",
|
|
740
|
+
);
|
|
741
|
+
});
|
|
742
|
+
});
|
|
743
|
+
//getTransactionCache
|
|
744
|
+
describe("api-test getTransactionCache", () => {
|
|
745
|
+
it("getTransactionCacheChain with not exist hash", async () => {
|
|
746
|
+
const request: GetTransactionCacheRequest = {
|
|
747
|
+
hash: "6eaaf19b9d73f646c051af7175a3c175410d2edfc1dad988cb6a6e171c4f902a",
|
|
748
|
+
};
|
|
749
|
+
let response: GetTransactionCacheChainResponse;
|
|
750
|
+
response = await baseService.getTransactionCacheChain(request);
|
|
751
|
+
expect(response.errorCode).to.equal(4);
|
|
752
|
+
expect(response.errorDesc).to.equal(
|
|
753
|
+
"The object does not exist, such as not being able to query accounts, TX, blocks, etc",
|
|
754
|
+
);
|
|
755
|
+
expect(response.success).to.equal(false);
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
it("getTransactionCachePlat with not exist hash", async () => {
|
|
759
|
+
const request: GetTransactionCacheRequest = {
|
|
760
|
+
hash: "6eaaf19b9d73f646c051af7175a3c175410d2edfc1dad988cb6a6e171c4f902a",
|
|
761
|
+
};
|
|
762
|
+
let response: GetTransactionCachePlatResponse;
|
|
763
|
+
response = await baseService.getTransactionCachePlat(request);
|
|
764
|
+
expect(response.errorCode).to.equal(4);
|
|
765
|
+
expect(response.errorDesc).to.equal(
|
|
766
|
+
"The object does not exist, such as not being able to query accounts, TX, blocks, etc",
|
|
767
|
+
);
|
|
768
|
+
expect(response.success).to.equal(false);
|
|
769
|
+
});
|
|
770
|
+
|
|
771
|
+
it("getTransactionCachePlat hash", async () => {
|
|
772
|
+
let platResponseJson = {
|
|
773
|
+
trace: "9d1450d34aac419b887b84567300050f",
|
|
774
|
+
result: {
|
|
775
|
+
total_count: 1,
|
|
776
|
+
transactions: [
|
|
777
|
+
{
|
|
778
|
+
blob: "0A286469643A6269643A6566433552456946657361427575315558624D4A577645737146526B514B697110F6880322330807522F0A296469643A6269643A65663262374A386141375044326D77535243754B4B4276423873726A4A7A32596F1080B51830C0843D3801",
|
|
779
|
+
hash: "e6366d3ae7231e8f59d44b710521dce671abd9d1c37c2e2b23736b12665e6547",
|
|
780
|
+
error_code: 1311,
|
|
781
|
+
signatures: [
|
|
782
|
+
{
|
|
783
|
+
sign_data:
|
|
784
|
+
"4BAC56FCF51A90CDD9DC30D7E13072FCFD3181BB861FA34457FD47E4515AC168013E17A8887F1A8EAE8DD42D42447B0644043DAFCF5C007DECF62D05033B1B03",
|
|
785
|
+
public_key:
|
|
786
|
+
"b065665b6fa23dc1c00b17b8d2cd86093c86bbae4c011247310f9160351bd64bc580cc",
|
|
787
|
+
},
|
|
788
|
+
],
|
|
789
|
+
transaction: {
|
|
790
|
+
operations: [
|
|
791
|
+
{
|
|
792
|
+
type: 7,
|
|
793
|
+
pay_coin: {
|
|
794
|
+
dest_address: "did:bid:ef2b7J8aA7PD2mwSRCuKKBvB8srjJz2Yo",
|
|
795
|
+
amount: 400000,
|
|
796
|
+
},
|
|
797
|
+
},
|
|
798
|
+
],
|
|
799
|
+
source_address: "did:bid:efC5REiFesaBuu1UXbMJWvEsqFRkQKiq",
|
|
800
|
+
nonce: 50294,
|
|
801
|
+
},
|
|
802
|
+
},
|
|
803
|
+
],
|
|
804
|
+
},
|
|
805
|
+
success: true,
|
|
806
|
+
error_code: 0,
|
|
807
|
+
error_desc: "ok",
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
let response: GetTransactionCachePlatResponse;
|
|
811
|
+
response = GetTransactionCachePlatResponse.fromJSON(platResponseJson);
|
|
812
|
+
expect(response.result?.transactions[0].hash).to.equal(
|
|
813
|
+
"e6366d3ae7231e8f59d44b710521dce671abd9d1c37c2e2b23736b12665e6547",
|
|
814
|
+
);
|
|
815
|
+
expect(response.result?.totalCount).to.equal(1);
|
|
816
|
+
});
|
|
817
|
+
});
|
|
818
|
+
//query/discard
|
|
819
|
+
describe("api-test query/discard", () => {
|
|
820
|
+
it("query/discard with no params", async () => {
|
|
821
|
+
const request: DiscardRequest = {};
|
|
822
|
+
let response: DiscardResponse;
|
|
823
|
+
response = await baseService.discard(request);
|
|
824
|
+
expect(response.errorCode).to.equal(0);
|
|
825
|
+
expect(response.errorDesc).to.equal("ok");
|
|
826
|
+
expect(response.success).to.equal(true);
|
|
827
|
+
expect(response.result?.count).to.be.greaterThan(0);
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
it("query/discard with hash", async () => {
|
|
831
|
+
const request: DiscardRequest = {
|
|
832
|
+
hash: "6eff3a70b7794578641ab7a5e56e3e14347a37b857174f3f92112e769b32f575",
|
|
833
|
+
};
|
|
834
|
+
let response: DiscardResponse;
|
|
835
|
+
response = await baseService.discard(request);
|
|
836
|
+
expect(response.errorCode).to.equal(0);
|
|
837
|
+
expect(response.errorDesc).to.equal("ok");
|
|
838
|
+
expect(response.success).to.equal(true);
|
|
839
|
+
expect(response.result?.count).to.equal(1);
|
|
840
|
+
expect(response.result?.transactionBases[0]?.hash).to.equal(
|
|
841
|
+
"6eff3a70b7794578641ab7a5e56e3e14347a37b857174f3f92112e769b32f575",
|
|
842
|
+
);
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
it("query/discard with not exist hash", async () => {
|
|
846
|
+
const request: DiscardRequest = {
|
|
847
|
+
hash: "6eff3a70b7794578641ab7a5e56e3e14347a37b857174f3f92112e769b32f576",
|
|
848
|
+
};
|
|
849
|
+
let response: DiscardResponse;
|
|
850
|
+
response = await baseService.discard(request);
|
|
851
|
+
expect(response.errorCode).to.equal(0);
|
|
852
|
+
expect(response.errorDesc).to.equal("ok");
|
|
853
|
+
expect(response.success).to.equal(true);
|
|
854
|
+
});
|
|
855
|
+
});
|
|
856
|
+
|
|
857
|
+
//query/discard
|
|
858
|
+
describe("api-test getTxCacheSize", () => {
|
|
859
|
+
it("getTxCacheSize", async () => {
|
|
860
|
+
let response: GetTxCacheSizeResponse;
|
|
861
|
+
response = await baseService.getTxCacheSize();
|
|
862
|
+
expect(response.errorCode).to.equal(0);
|
|
863
|
+
expect(response.errorDesc).to.equal("ok");
|
|
864
|
+
expect(response.success).to.equal(true);
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
});
|