@thalalabs/surf 0.0.16 → 1.0.1
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 +12 -0
- package/README.md +44 -45
- package/build/cjs/core/Client.js +55 -41
- package/build/cjs/core/Client.js.map +1 -1
- package/build/cjs/core/WalletClient.js +20 -31
- package/build/cjs/core/WalletClient.js.map +1 -1
- package/build/cjs/core/createEntryPayload.js +9 -91
- package/build/cjs/core/createEntryPayload.js.map +1 -1
- package/build/cjs/core/createViewPayload.js +26 -52
- package/build/cjs/core/createViewPayload.js.map +1 -1
- package/build/cjs/core/index.js +2 -2
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/ensureTypes.js.map +1 -1
- package/build/cjs/hooks/index.js.map +1 -1
- package/build/cjs/hooks/useSubmitTransaction.js +25 -46
- package/build/cjs/hooks/useSubmitTransaction.js.map +1 -1
- package/build/cjs/hooks/useWalletClient.js +2 -2
- package/build/cjs/hooks/useWalletClient.js.map +1 -1
- package/build/cjs/index.js +2 -2
- package/build/cjs/index.js.map +1 -1
- package/build/esm/core/Client.js +53 -39
- package/build/esm/core/Client.js.map +1 -1
- package/build/esm/core/WalletClient.js +20 -31
- package/build/esm/core/WalletClient.js.map +1 -1
- package/build/esm/core/createEntryPayload.js +9 -91
- package/build/esm/core/createEntryPayload.js.map +1 -1
- package/build/esm/core/createViewPayload.js +26 -52
- package/build/esm/core/createViewPayload.js.map +1 -1
- package/build/esm/core/index.js +1 -1
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/ensureTypes.js.map +1 -1
- package/build/esm/hooks/index.js.map +1 -1
- package/build/esm/hooks/useSubmitTransaction.js +25 -46
- package/build/esm/hooks/useSubmitTransaction.js.map +1 -1
- package/build/esm/hooks/useWalletClient.js +2 -2
- package/build/esm/hooks/useWalletClient.js.map +1 -1
- package/build/esm/index.js +1 -1
- package/build/esm/index.js.map +1 -1
- package/build/types/core/Client.d.ts +61 -48
- package/build/types/core/Client.d.ts.map +1 -1
- package/build/types/core/WalletClient.d.ts +3 -5
- package/build/types/core/WalletClient.d.ts.map +1 -1
- package/build/types/core/createEntryPayload.d.ts +8 -8
- package/build/types/core/createEntryPayload.d.ts.map +1 -1
- package/build/types/core/createViewPayload.d.ts +4 -4
- package/build/types/core/createViewPayload.d.ts.map +1 -1
- package/build/types/core/index.d.ts +1 -1
- package/build/types/core/index.d.ts.map +1 -1
- package/build/types/ensureTypes.d.ts.map +1 -1
- package/build/types/hooks/index.d.ts +1 -1
- package/build/types/hooks/index.d.ts.map +1 -1
- package/build/types/hooks/useSubmitTransaction.d.ts +3 -11
- package/build/types/hooks/useSubmitTransaction.d.ts.map +1 -1
- package/build/types/hooks/useWalletClient.d.ts +1 -3
- package/build/types/hooks/useWalletClient.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/types/abi.d.ts.map +1 -1
- package/build/types/types/client/abiClient.d.ts +12 -16
- package/build/types/types/client/abiClient.d.ts.map +1 -1
- package/build/types/types/client/client.d.ts +11 -23
- package/build/types/types/client/client.d.ts.map +1 -1
- package/build/types/types/convertor/argsConvertor.d.ts +1 -1
- package/build/types/types/convertor/argsConvertor.d.ts.map +1 -1
- package/build/types/types/convertor/genericConvertor.d.ts.map +1 -1
- package/build/types/types/convertor/returnConvertor.d.ts +1 -1
- package/build/types/types/index.d.ts +1 -1
- package/build/types/types/index.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/core/Client.ts +110 -114
- package/src/core/WalletClient.ts +21 -31
- package/src/core/__tests__/accountResource.test.ts +56 -54
- package/src/core/__tests__/createEntryPayload.test.ts +34 -34
- package/src/core/__tests__/createViewPayload.test.ts +94 -111
- package/src/core/__tests__/option.test.ts +38 -31
- package/src/core/__tests__/submitTransaction.test.ts +58 -26
- package/src/core/__tests__/useABI.test.ts +38 -38
- package/src/core/__tests__/view.test.ts +36 -30
- package/src/core/__tests__/view_vector.test.ts +52 -50
- package/src/core/createEntryPayload.ts +24 -143
- package/src/core/createViewPayload.ts +40 -68
- package/src/core/index.ts +1 -1
- package/src/ensureTypes.ts +1 -0
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useSubmitTransaction.ts +35 -68
- package/src/hooks/useWalletClient.ts +2 -2
- package/src/index.ts +1 -1
- package/src/types/abi.ts +1 -0
- package/src/types/client/abiClient.ts +12 -16
- package/src/types/client/client.ts +11 -25
- package/src/types/convertor/argsConvertor.ts +1 -1
- package/src/types/convertor/genericConvertor.ts +2 -0
- package/src/types/convertor/returnConvertor.ts +3 -3
- package/src/types/index.ts +0 -2
|
@@ -2,37 +2,40 @@
|
|
|
2
2
|
* These test cases depends on network, it call the real contract.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { AptosAccount } from 'aptos';
|
|
6
5
|
import { COIN_ABI } from '../../abi/coin';
|
|
7
|
-
import {
|
|
8
|
-
import { createEntryPayload } from '../createEntryPayload';
|
|
6
|
+
import { createSurfClient } from '../Client.js';
|
|
7
|
+
import { createEntryPayload } from '../createEntryPayload.js';
|
|
8
|
+
import { Account, Aptos, AptosConfig, Ed25519PrivateKey, Network } from '@aptos-labs/ts-sdk';
|
|
9
9
|
|
|
10
10
|
describe('call entry functions', () => {
|
|
11
|
-
const client =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const account = new AptosAccount(
|
|
16
|
-
undefined,
|
|
17
|
-
'0xac914efd2367c7aa42c95d100592c099e487d2270bf0e0761e5fe93ff4016593',
|
|
11
|
+
const client = createSurfClient(
|
|
12
|
+
new Aptos(
|
|
13
|
+
new AptosConfig({ network: Network.TESTNET })
|
|
14
|
+
)
|
|
18
15
|
);
|
|
19
16
|
|
|
17
|
+
const account = Account.fromPrivateKey({ privateKey: new Ed25519PrivateKey("0x4b0a52d0b047b6868d9650fdb9b61720e361ba74f40571635fec0694a838eb98") });
|
|
18
|
+
|
|
20
19
|
// Act before assertions
|
|
21
|
-
beforeAll(async () => {});
|
|
20
|
+
beforeAll(async () => { });
|
|
22
21
|
|
|
23
22
|
// Teardown (cleanup) after assertions
|
|
24
|
-
afterAll(() => {});
|
|
23
|
+
afterAll(() => { });
|
|
25
24
|
|
|
26
25
|
it('basic', async () => {
|
|
27
26
|
const entryPayload = createEntryPayload(COIN_ABI, {
|
|
28
27
|
function: 'transfer',
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
functionArguments: ['0x1', 1],
|
|
29
|
+
typeArguments: ['0x1::aptos_coin::AptosCoin'],
|
|
31
30
|
});
|
|
32
31
|
|
|
33
|
-
const result = await client.simulateTransaction(
|
|
32
|
+
const result = await client.simulateTransaction({
|
|
33
|
+
payload: entryPayload,
|
|
34
|
+
sender: account.accountAddress,
|
|
35
|
+
publicKey: account.publicKey,
|
|
36
|
+
});
|
|
34
37
|
|
|
35
|
-
expect(result
|
|
38
|
+
expect(result?.hash).toBeDefined();
|
|
36
39
|
expect((result as any).payload).toMatchInlineSnapshot(`
|
|
37
40
|
{
|
|
38
41
|
"arguments": [
|
|
@@ -51,13 +54,17 @@ describe('call entry functions', () => {
|
|
|
51
54
|
it('vector', async () => {
|
|
52
55
|
const entryPayload = createEntryPayload(TEST_ABI, {
|
|
53
56
|
function: 'test_run_function',
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
functionArguments: [[1, 2, 3, 10, 20, 30]],
|
|
58
|
+
typeArguments: [],
|
|
56
59
|
});
|
|
57
60
|
|
|
58
|
-
const result = await client.simulateTransaction(
|
|
61
|
+
const result = await client.simulateTransaction({
|
|
62
|
+
payload: entryPayload,
|
|
63
|
+
sender: account.accountAddress,
|
|
64
|
+
publicKey: account.publicKey,
|
|
65
|
+
});
|
|
59
66
|
|
|
60
|
-
expect(result
|
|
67
|
+
expect(result?.hash).toBeDefined();
|
|
61
68
|
expect((result as any).payload).toMatchInlineSnapshot(`
|
|
62
69
|
{
|
|
63
70
|
"arguments": [
|
|
@@ -71,20 +78,45 @@ describe('call entry functions', () => {
|
|
|
71
78
|
}, 60000);
|
|
72
79
|
|
|
73
80
|
it('vector<u8>', async () => {
|
|
74
|
-
const inputString =
|
|
81
|
+
const inputString = [1,2,34];
|
|
82
|
+
const entryPayload = createEntryPayload(TEST_ABI, {
|
|
83
|
+
function: 'test_run_function',
|
|
84
|
+
functionArguments: [inputString],
|
|
85
|
+
typeArguments: [],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const result = await client.simulateTransaction({
|
|
89
|
+
payload: entryPayload,
|
|
90
|
+
sender: account.accountAddress,
|
|
91
|
+
publicKey: account.publicKey,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
expect(result?.hash).toBeDefined();
|
|
95
|
+
expect((result as any).payload.arguments[0]).toEqual("0x010222");
|
|
96
|
+
}, 60000);
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
it('vector<u8> hex string', async () => {
|
|
100
|
+
const inputString = "0x1234";
|
|
75
101
|
const entryPayload = createEntryPayload(TEST_ABI, {
|
|
76
102
|
function: 'test_run_function',
|
|
77
|
-
|
|
78
|
-
|
|
103
|
+
functionArguments: [inputString],
|
|
104
|
+
typeArguments: [],
|
|
79
105
|
});
|
|
80
106
|
|
|
81
|
-
const result = await client.simulateTransaction(
|
|
107
|
+
const result = await client.simulateTransaction({
|
|
108
|
+
payload: entryPayload,
|
|
109
|
+
sender: account.accountAddress,
|
|
110
|
+
publicKey: account.publicKey,
|
|
111
|
+
});
|
|
82
112
|
|
|
83
|
-
expect(result
|
|
84
|
-
expect((result as any).payload.arguments[0]).toEqual("
|
|
113
|
+
expect(result?.hash).toBeDefined();
|
|
114
|
+
expect((result as any).payload.arguments[0]).toEqual("0x1234");
|
|
85
115
|
}, 60000);
|
|
86
116
|
});
|
|
87
117
|
|
|
118
|
+
|
|
119
|
+
|
|
88
120
|
const TEST_ABI = {
|
|
89
121
|
address: '0x3d097bb505c9e5d8a96e367f371168240025877f6be8d4a88eacaafb709fe5c9',
|
|
90
122
|
name: 'test',
|
|
@@ -2,78 +2,77 @@
|
|
|
2
2
|
* These test cases depends on network, it call the real contract.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { AptosAccount } from 'aptos';
|
|
6
5
|
import { COIN_ABI } from '../../abi/coin';
|
|
7
|
-
import {
|
|
6
|
+
import { createSurfClient } from '../Client';
|
|
7
|
+
import { Account, Aptos, AptosConfig, Ed25519PrivateKey, Network } from '@aptos-labs/ts-sdk';
|
|
8
8
|
|
|
9
9
|
describe('useABI', () => {
|
|
10
|
-
const client =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const account = new AptosAccount(
|
|
15
|
-
undefined,
|
|
16
|
-
'0xac914efd2367c7aa42c95d100592c099e487d2270bf0e0761e5fe93ff4016593',
|
|
10
|
+
const client = createSurfClient(
|
|
11
|
+
new Aptos(
|
|
12
|
+
new AptosConfig({ network: Network.TESTNET })
|
|
13
|
+
)
|
|
17
14
|
);
|
|
18
15
|
|
|
16
|
+
const account = Account.fromPrivateKey({ privateKey: new Ed25519PrivateKey("0x4b0a52d0b047b6868d9650fdb9b61720e361ba74f40571635fec0694a838eb98") });
|
|
17
|
+
|
|
19
18
|
// Act before assertions
|
|
20
|
-
beforeAll(async () => {});
|
|
19
|
+
beforeAll(async () => { });
|
|
21
20
|
|
|
22
21
|
// Teardown (cleanup) after assertions
|
|
23
|
-
afterAll(() => {});
|
|
22
|
+
afterAll(() => { });
|
|
24
23
|
|
|
25
24
|
it('basic type checking', async () => {
|
|
26
25
|
// no need to run, type check only
|
|
27
26
|
() => {
|
|
28
27
|
// @ts-expect-error cannot call a function not exist
|
|
29
28
|
client.useABI(COIN_ABI).view.not_exist_func({
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
functionArguments: ['0x1'],
|
|
30
|
+
typeArguments: ['0x1::aptos_coin::AptosCoin'],
|
|
32
31
|
});
|
|
33
32
|
|
|
34
33
|
// @ts-expect-error cannot call a entry function from view
|
|
35
34
|
client.useABI(COIN_ABI).view.transfer({
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
functionArguments: ['0x1'],
|
|
36
|
+
typeArguments: ['0x1::aptos_coin::AptosCoin'],
|
|
38
37
|
});
|
|
39
38
|
|
|
40
39
|
// @ts-expect-error cannot call a view function from entry
|
|
41
40
|
client.useABI(COIN_ABI).entry.balance({
|
|
42
41
|
arguments: ['0x1'],
|
|
43
|
-
|
|
42
|
+
typeArguments: ['0x1::aptos_coin::AptosCoin'],
|
|
44
43
|
});
|
|
45
44
|
|
|
46
45
|
client.useABI(TEST_ABI).view.address_as_input({
|
|
47
46
|
// @ts-expect-error require two args
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
functionArguments: ['0x1'],
|
|
48
|
+
typeArguments: [],
|
|
50
49
|
});
|
|
51
50
|
|
|
52
51
|
client.useABI(TEST_ABI).view.address_as_input({
|
|
53
52
|
// @ts-expect-error require address
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
functionArguments: ['0x1', 1],
|
|
54
|
+
typeArguments: [],
|
|
56
55
|
});
|
|
57
56
|
|
|
58
57
|
client.useABI(COIN_ABI).entry.transfer({
|
|
59
|
-
|
|
58
|
+
functionArguments: ['0x1', 1],
|
|
60
59
|
// @ts-expect-error require a type argument
|
|
61
|
-
|
|
60
|
+
typeArguments: [],
|
|
62
61
|
account,
|
|
63
62
|
});
|
|
64
63
|
|
|
65
64
|
// @ts-expect-error account is required for entry function
|
|
66
65
|
client.useABI(COIN_ABI).entry.transfer({
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
functionArguments: ['0x1', 1],
|
|
67
|
+
typeArguments: ['0x1::aptos_coin::AptosCoin'],
|
|
69
68
|
});
|
|
70
69
|
};
|
|
71
70
|
});
|
|
72
71
|
|
|
73
72
|
it('view', async () => {
|
|
74
73
|
const result = await client.useABI(COIN_ABI).view.name({
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
functionArguments: [],
|
|
75
|
+
typeArguments: ['0x1::aptos_coin::AptosCoin'],
|
|
77
76
|
});
|
|
78
77
|
expect(result).toMatchInlineSnapshot(`
|
|
79
78
|
[
|
|
@@ -82,8 +81,8 @@ describe('useABI', () => {
|
|
|
82
81
|
`);
|
|
83
82
|
|
|
84
83
|
const result2 = await client.useABI(COIN_ABI).view.decimals({
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
functionArguments: [],
|
|
85
|
+
typeArguments: ['0x1::aptos_coin::AptosCoin'],
|
|
87
86
|
});
|
|
88
87
|
expect(result2).toMatchInlineSnapshot(`
|
|
89
88
|
[
|
|
@@ -94,25 +93,26 @@ describe('useABI', () => {
|
|
|
94
93
|
|
|
95
94
|
it('view with ledger version', async () => {
|
|
96
95
|
const result = await client.useABI(COIN_ABI).view.balance({
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
functionArguments: ['0x1'],
|
|
97
|
+
typeArguments: ['0x1::aptos_coin::AptosCoin'],
|
|
98
|
+
ledgerVersion: '562606728',
|
|
100
99
|
});
|
|
101
100
|
expect(result).toMatchInlineSnapshot(`
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
[
|
|
102
|
+
"50000358",
|
|
103
|
+
]
|
|
104
|
+
`);
|
|
106
105
|
}, 60000);
|
|
107
106
|
|
|
108
107
|
it('entry', async () => {
|
|
109
108
|
const result = await client.useABI(COIN_ABI).entry.transfer({
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
functionArguments: ['0x1', 1],
|
|
110
|
+
typeArguments: ['0x1::aptos_coin::AptosCoin'],
|
|
112
111
|
account,
|
|
113
112
|
isSimulation: true,
|
|
114
113
|
});
|
|
115
|
-
|
|
114
|
+
|
|
115
|
+
expect(result?.hash).toBeDefined();
|
|
116
116
|
expect((result as any).payload).toMatchInlineSnapshot(`
|
|
117
117
|
{
|
|
118
118
|
"arguments": [
|
|
@@ -2,32 +2,36 @@
|
|
|
2
2
|
* These test cases depends on network, it call the real contract.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { Aptos, AptosConfig, Network } from '@aptos-labs/ts-sdk';
|
|
6
|
+
import { COIN_ABI } from '../../abi/coin.js';
|
|
7
|
+
import { createSurfClient } from '../Client.js';
|
|
8
|
+
import { createViewPayload } from '../createViewPayload.js';
|
|
8
9
|
|
|
9
10
|
describe('call view functions', () => {
|
|
10
|
-
const client =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
const client = createSurfClient(
|
|
12
|
+
new Aptos(
|
|
13
|
+
new AptosConfig({ network: Network.TESTNET })
|
|
14
|
+
)
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const clientMain = createSurfClient(
|
|
18
|
+
new Aptos(
|
|
19
|
+
new AptosConfig({ network: Network.MAINNET })
|
|
20
|
+
)
|
|
21
|
+
);
|
|
18
22
|
// Act before assertions
|
|
19
|
-
beforeAll(async () => {});
|
|
23
|
+
beforeAll(async () => { });
|
|
20
24
|
|
|
21
25
|
// Teardown (cleanup) after assertions
|
|
22
|
-
afterAll(() => {});
|
|
26
|
+
afterAll(() => { });
|
|
23
27
|
|
|
24
28
|
it('basic', async () => {
|
|
25
29
|
const viewPayload = createViewPayload(COIN_ABI, {
|
|
26
30
|
function: 'name',
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
functionArguments: [],
|
|
32
|
+
typeArguments: ['0x1::aptos_coin::AptosCoin'],
|
|
29
33
|
});
|
|
30
|
-
const result = await client.view(viewPayload);
|
|
34
|
+
const result = await client.view({ payload: viewPayload });
|
|
31
35
|
expect(result).toMatchInlineSnapshot(`
|
|
32
36
|
[
|
|
33
37
|
"Aptos Coin",
|
|
@@ -36,10 +40,10 @@ describe('call view functions', () => {
|
|
|
36
40
|
|
|
37
41
|
const viewPayload2 = createViewPayload(COIN_ABI, {
|
|
38
42
|
function: 'decimals',
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
functionArguments: [],
|
|
44
|
+
typeArguments: ['0x1::aptos_coin::AptosCoin'],
|
|
41
45
|
});
|
|
42
|
-
const result2 = await client.view(viewPayload2);
|
|
46
|
+
const result2 = await client.view({ payload: viewPayload2 });
|
|
43
47
|
expect(result2).toMatchInlineSnapshot(`
|
|
44
48
|
[
|
|
45
49
|
8,
|
|
@@ -50,29 +54,31 @@ describe('call view functions', () => {
|
|
|
50
54
|
it('ledger version', async () => {
|
|
51
55
|
const viewPayload = createViewPayload(COIN_ABI, {
|
|
52
56
|
function: 'balance',
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
functionArguments: ['0x1'],
|
|
58
|
+
typeArguments: ['0x1::aptos_coin::AptosCoin'],
|
|
55
59
|
});
|
|
56
|
-
const result = await client.view(
|
|
57
|
-
|
|
60
|
+
const result = await client.view({
|
|
61
|
+
payload: viewPayload, options: {
|
|
62
|
+
ledgerVersion: 562606728,
|
|
63
|
+
}
|
|
58
64
|
});
|
|
59
65
|
expect(result).toMatchInlineSnapshot(`
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
[
|
|
67
|
+
"50000358",
|
|
68
|
+
]
|
|
69
|
+
`);
|
|
64
70
|
}, 60000);
|
|
65
71
|
|
|
66
72
|
it('return struct', async () => {
|
|
67
73
|
const viewPayload = createViewPayload(TIERED_ORACLE_ABI, {
|
|
68
74
|
function: 'get_last_price',
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
functionArguments: [],
|
|
76
|
+
typeArguments: ['0x1::aptos_coin::AptosCoin'],
|
|
71
77
|
});
|
|
72
78
|
|
|
73
79
|
// The declaration in Move:
|
|
74
80
|
// struct FixedPoint64 has copy, drop, store { value: u128 }
|
|
75
|
-
const result = await clientMain.view(viewPayload);
|
|
81
|
+
const result = await clientMain.view({ payload: viewPayload });
|
|
76
82
|
expect(result.length).toBe(1);
|
|
77
83
|
expect((result[0] as any).v).toBeDefined();
|
|
78
84
|
expect(typeof (result[0] as any).v).toEqual('string');
|
|
@@ -2,28 +2,30 @@
|
|
|
2
2
|
* These test cases depends on network, it call the real contract.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { Aptos, AptosConfig, Network } from '@aptos-labs/ts-sdk';
|
|
6
|
+
import { createSurfClient } from '../Client.js';
|
|
7
|
+
import { createViewPayload } from '../createViewPayload.js';
|
|
7
8
|
|
|
8
9
|
// TODO: add vector<address>, vector<vector>
|
|
9
10
|
describe('call view functions for vector type', () => {
|
|
10
|
-
const client =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const client = createSurfClient(
|
|
12
|
+
new Aptos(
|
|
13
|
+
new AptosConfig({ network: Network.TESTNET })
|
|
14
|
+
)
|
|
15
|
+
);
|
|
14
16
|
// Act before assertions
|
|
15
|
-
beforeAll(async () => {});
|
|
17
|
+
beforeAll(async () => { });
|
|
16
18
|
|
|
17
19
|
// Teardown (cleanup) after assertions
|
|
18
|
-
afterAll(() => {});
|
|
20
|
+
afterAll(() => { });
|
|
19
21
|
|
|
20
22
|
it('vector_bool', async () => {
|
|
21
23
|
const viewPayload = createViewPayload(TEST_ABI, {
|
|
22
24
|
function: 'test_view_function_bool',
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
functionArguments: [[true, false, false, true, true]],
|
|
26
|
+
typeArguments: [],
|
|
25
27
|
});
|
|
26
|
-
const result = await client.view(viewPayload);
|
|
28
|
+
const result = await client.view({ payload: viewPayload });
|
|
27
29
|
expect(result).toMatchInlineSnapshot(`
|
|
28
30
|
[
|
|
29
31
|
3,
|
|
@@ -31,13 +33,13 @@ describe('call view functions for vector type', () => {
|
|
|
31
33
|
`);
|
|
32
34
|
}, 60000);
|
|
33
35
|
|
|
34
|
-
it('vector_u8', async () => {
|
|
36
|
+
it('vector_u8 array', async () => {
|
|
35
37
|
const viewPayload = createViewPayload(TEST_ABI, {
|
|
36
38
|
function: 'test_view_function_u8',
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
functionArguments: [[1, 2, 3, 10, 50]],
|
|
40
|
+
typeArguments: [],
|
|
39
41
|
});
|
|
40
|
-
const result = await client.view(viewPayload);
|
|
42
|
+
const result = await client.view({ payload: viewPayload });
|
|
41
43
|
expect(result).toMatchInlineSnapshot(`
|
|
42
44
|
[
|
|
43
45
|
66,
|
|
@@ -45,16 +47,16 @@ describe('call view functions for vector type', () => {
|
|
|
45
47
|
`);
|
|
46
48
|
}, 60000);
|
|
47
49
|
|
|
48
|
-
it('vector_u8', async () => {
|
|
50
|
+
it('vector_u8 string', async () => {
|
|
49
51
|
const viewPayload = createViewPayload(TEST_ABI, {
|
|
50
52
|
function: 'test_view_function_u8',
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
functionArguments: ["0x010234"],
|
|
54
|
+
typeArguments: [],
|
|
53
55
|
});
|
|
54
|
-
const result = await client.view(viewPayload);
|
|
56
|
+
const result = await client.view({ payload: viewPayload });
|
|
55
57
|
expect(result).toMatchInlineSnapshot(`
|
|
56
58
|
[
|
|
57
|
-
|
|
59
|
+
55,
|
|
58
60
|
]
|
|
59
61
|
`);
|
|
60
62
|
}, 60000);
|
|
@@ -62,10 +64,10 @@ describe('call view functions for vector type', () => {
|
|
|
62
64
|
it('vector_u16', async () => {
|
|
63
65
|
const viewPayload = createViewPayload(TEST_ABI, {
|
|
64
66
|
function: 'test_view_function_u16',
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
functionArguments: [[256, 100]],
|
|
68
|
+
typeArguments: [],
|
|
67
69
|
});
|
|
68
|
-
const result = await client.view(viewPayload);
|
|
70
|
+
const result = await client.view({ payload: viewPayload });
|
|
69
71
|
expect(result).toMatchInlineSnapshot(`
|
|
70
72
|
[
|
|
71
73
|
356,
|
|
@@ -76,10 +78,10 @@ describe('call view functions for vector type', () => {
|
|
|
76
78
|
it('vector_u32', async () => {
|
|
77
79
|
const viewPayload = createViewPayload(TEST_ABI, {
|
|
78
80
|
function: 'test_view_function_u32',
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
functionArguments: [[70000, 100]],
|
|
82
|
+
typeArguments: [],
|
|
81
83
|
});
|
|
82
|
-
const result = await client.view(viewPayload);
|
|
84
|
+
const result = await client.view({ payload: viewPayload });
|
|
83
85
|
expect(result).toMatchInlineSnapshot(`
|
|
84
86
|
[
|
|
85
87
|
70100,
|
|
@@ -90,46 +92,46 @@ describe('call view functions for vector type', () => {
|
|
|
90
92
|
it('vector_u64', async () => {
|
|
91
93
|
const viewPayload = createViewPayload(TEST_ABI, {
|
|
92
94
|
function: 'test_view_function_u64',
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
functionArguments: [[BigInt('4294967296'), 100]],
|
|
96
|
+
typeArguments: [],
|
|
95
97
|
});
|
|
96
|
-
const result = await client.view(viewPayload);
|
|
98
|
+
const result = await client.view({ payload: viewPayload });
|
|
97
99
|
expect(result).toMatchInlineSnapshot(`
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
[
|
|
101
|
+
"4294967396",
|
|
102
|
+
]
|
|
103
|
+
`);
|
|
102
104
|
}, 60000);
|
|
103
105
|
|
|
104
106
|
it('vector_u256', async () => {
|
|
105
107
|
const viewPayload = createViewPayload(TEST_ABI, {
|
|
106
108
|
function: 'test_view_function_u256',
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
functionArguments: [[BigInt('4294967296'), 100]],
|
|
110
|
+
typeArguments: [],
|
|
109
111
|
});
|
|
110
|
-
const result = await client.view(viewPayload);
|
|
112
|
+
const result = await client.view({ payload: viewPayload });
|
|
111
113
|
expect(result).toMatchInlineSnapshot(`
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
[
|
|
115
|
+
"4294967396",
|
|
116
|
+
]
|
|
117
|
+
`);
|
|
116
118
|
}, 60000);
|
|
117
119
|
|
|
118
120
|
it('return vector', async () => {
|
|
119
121
|
const viewPayload = createViewPayload(TEST_ABI, {
|
|
120
122
|
function: 'test_view_function_u64_return_vector',
|
|
121
|
-
|
|
122
|
-
|
|
123
|
+
functionArguments: [[BigInt('4294967296'), 100]],
|
|
124
|
+
typeArguments: [],
|
|
123
125
|
});
|
|
124
|
-
const result = await client.view(viewPayload);
|
|
126
|
+
const result = await client.view({ payload: viewPayload });
|
|
125
127
|
expect(result).toMatchInlineSnapshot(`
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
[
|
|
129
|
+
[
|
|
130
|
+
"4294967296",
|
|
131
|
+
"100",
|
|
132
|
+
],
|
|
133
|
+
]
|
|
134
|
+
`);
|
|
133
135
|
}, 60000);
|
|
134
136
|
});
|
|
135
137
|
|