suidouble 0.0.45 → 0.0.47
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/index.js +4 -3
- package/lib/SuiCliCommands.js +3 -1
- package/lib/SuiCoin.js +15 -1
- package/lib/SuiCommonMethods.js +0 -1
- package/lib/SuiEvent.js +1 -1
- package/lib/SuiInBrowser.js +3 -2
- package/lib/SuiLocalTestValidator.js +5 -3
- package/lib/SuiMaster.js +54 -21
- package/lib/SuiObject.js +4 -4
- package/lib/SuiPackage.js +7 -7
- package/lib/SuiPackageModule.js +6 -4
- package/lib/SuiPaginatedResponse.js +0 -1
- package/lib/SuiPseudoRandomAddress.js +1 -1
- package/package.json +1 -1
- package/test/coins.test.js +111 -0
package/index.js
CHANGED
|
@@ -3,7 +3,8 @@ const SuiInBrowser = require('./lib/SuiInBrowser.js');
|
|
|
3
3
|
const SuiTestScenario = require('./lib/SuiTestScenario.js');
|
|
4
4
|
const SuiObject = require('./lib/SuiObject.js');
|
|
5
5
|
const SuiLocalTestValidator = require('./lib/SuiLocalTestValidator.js');
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
const { TransactionBlock,Transactions } = require('@mysten/sui.js/transactions');
|
|
7
8
|
|
|
8
9
|
module.exports = {
|
|
9
10
|
SuiMaster,
|
|
@@ -13,6 +14,6 @@ module.exports = {
|
|
|
13
14
|
SuiLocalTestValidator,
|
|
14
15
|
MIST_PER_SUI: SuiMaster.MIST_PER_SUI,
|
|
15
16
|
|
|
16
|
-
TransactionBlock:
|
|
17
|
-
Transactions:
|
|
17
|
+
TransactionBlock: TransactionBlock,
|
|
18
|
+
Transactions: Transactions,
|
|
18
19
|
};
|
package/lib/SuiCliCommands.js
CHANGED
package/lib/SuiCoin.js
CHANGED
|
@@ -66,7 +66,21 @@ class SuiCoin {
|
|
|
66
66
|
|
|
67
67
|
const str = (''+BigInt(amount)).padStart(this.decimals + 1,'0');
|
|
68
68
|
const ind = str.length - this.decimals;
|
|
69
|
-
|
|
69
|
+
let asFloatString = str.substring(0, ind) + '.' + str.substring(ind);
|
|
70
|
+
|
|
71
|
+
/// yep, I can't find a better way to strip extra 0 at the end. All regexes are not ok. Ping me if you have a good one
|
|
72
|
+
let i = asFloatString.length - 1;
|
|
73
|
+
let haveNotMetNoZero = false;
|
|
74
|
+
while (i > 0 && !haveNotMetNoZero) {
|
|
75
|
+
if (asFloatString.substring(i, i+1) === '0' && asFloatString.substring(i-1, i) !== '.') {
|
|
76
|
+
asFloatString = asFloatString.substring(0, i);
|
|
77
|
+
} else {
|
|
78
|
+
haveNotMetNoZero = true;
|
|
79
|
+
}
|
|
80
|
+
i--;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return asFloatString;
|
|
70
84
|
}
|
|
71
85
|
|
|
72
86
|
get suiMaster() {
|
package/lib/SuiCommonMethods.js
CHANGED
|
@@ -25,7 +25,6 @@ class SuiCommonMethods extends EventTarget {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
let prefix = (this._suiMaster ? (''+this._suiMaster.instanceN+' |') : (this.instanceN ? ''+this.instanceN+' |' : '') );
|
|
28
|
-
// prefix += this.constructor.name+' | ';
|
|
29
28
|
|
|
30
29
|
args.unshift(this.constructor.name+' |');
|
|
31
30
|
args.unshift(prefix);
|
package/lib/SuiEvent.js
CHANGED
package/lib/SuiInBrowser.js
CHANGED
|
@@ -2,7 +2,8 @@ const SuiCommonMethods = require('./SuiCommonMethods.js');
|
|
|
2
2
|
const SuiInBrowserAdapter = require('./SuiInBrowserAdapter.js');
|
|
3
3
|
const WalletsStandardCore = require('@wallet-standard/core');
|
|
4
4
|
const icons = require('./data/icons.json');
|
|
5
|
-
const {
|
|
5
|
+
const { SuiClient, getFullnodeUrl } = require('@mysten/sui.js/client');
|
|
6
|
+
|
|
6
7
|
const SuiMaster = require('./SuiMaster.js');
|
|
7
8
|
|
|
8
9
|
const DEFAULT_CHAIN = 'sui:devnet';
|
|
@@ -181,7 +182,7 @@ class SuiInBrowser extends SuiCommonMethods {
|
|
|
181
182
|
throw new Error('invalid chain: '+chainName);
|
|
182
183
|
}
|
|
183
184
|
|
|
184
|
-
this._provider = new
|
|
185
|
+
this._provider = new SuiClient({url: chainSettings[chainName].fullnode});
|
|
185
186
|
this._suiMaster = new SuiMaster({
|
|
186
187
|
debug: this._debug,
|
|
187
188
|
signer: this,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// const { spawn } = require('child_process');
|
|
2
2
|
const SuiCliCommands = require('./SuiCliCommands.js');
|
|
3
3
|
const SuiCommonMethods = require('./SuiCommonMethods.js');
|
|
4
|
-
const { JsonRpcProvider, localnetConnection, devnetConnection } = require('@mysten/sui.js');
|
|
4
|
+
// const { JsonRpcProvider, localnetConnection, devnetConnection } = require('@mysten/sui.js');
|
|
5
|
+
|
|
6
|
+
const { SuiClient, getFullnodeUrl } = require('@mysten/sui.js/client');
|
|
5
7
|
|
|
6
8
|
class SuiLocalTestValidator extends SuiCommonMethods {
|
|
7
9
|
constructor(params = {}) {
|
|
@@ -28,10 +30,10 @@ class SuiLocalTestValidator extends SuiCommonMethods {
|
|
|
28
30
|
|
|
29
31
|
get provider() {
|
|
30
32
|
if (this._providerName === 'sui:localnet') {
|
|
31
|
-
return new
|
|
33
|
+
return new SuiClient({url: getFullnodeUrl('localnet')});
|
|
32
34
|
} else if (this._providerName === 'sui:devnet') {
|
|
33
35
|
// if testFallbackEnabled == true and we can't start local node
|
|
34
|
-
return new JsonRpcProvider(devnetConnection);
|
|
36
|
+
return new SuiClient({url: getFullnodeUrl('devnet')});//JsonRpcProvider(devnetConnection);
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
|
package/lib/SuiMaster.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const sui = require('@mysten/sui.js');
|
|
2
1
|
const SuiCommonMethods = require('./SuiCommonMethods.js');
|
|
3
2
|
const SuiPackage = require('./SuiPackage.js');
|
|
4
3
|
const SuiPseudoRandomAddress = require('./SuiPseudoRandomAddress.js');
|
|
@@ -8,6 +7,10 @@ const SuiObject = require('./SuiObject.js');
|
|
|
8
7
|
const SuiTransaction = require('./SuiTransaction.js');
|
|
9
8
|
const SuiEvent = require('./SuiEvent.js');
|
|
10
9
|
const SuiCoins = require('./SuiCoins.js');
|
|
10
|
+
const { SuiClient, getFullnodeUrl } = require('@mysten/sui.js/client');
|
|
11
|
+
const { MIST_PER_SUI } = require('@mysten/sui.js/utils');
|
|
12
|
+
const { Ed25519Keypair } = require('@mysten/sui.js/keypairs/ed25519');
|
|
13
|
+
const { requestSuiFromFaucetV0, getFaucetHost } = require('@mysten/sui.js/faucet');
|
|
11
14
|
|
|
12
15
|
class SuiMaster extends SuiCommonMethods {
|
|
13
16
|
constructor(params = {}) {
|
|
@@ -31,11 +34,11 @@ class SuiMaster extends SuiCommonMethods {
|
|
|
31
34
|
this._keypair = params.keypair;
|
|
32
35
|
} else if (params.phrase) {
|
|
33
36
|
if (!params.accountIndex) {
|
|
34
|
-
this._keypair =
|
|
37
|
+
this._keypair = Ed25519Keypair.deriveKeypair(params.phrase);
|
|
35
38
|
} else {
|
|
36
39
|
// remember you can generate many addresses with same seed?
|
|
37
40
|
const derivePath = `m/44'/784'/${params.accountIndex}'/0'/0'`;
|
|
38
|
-
this._keypair =
|
|
41
|
+
this._keypair = Ed25519Keypair.deriveKeypair(params.phrase, derivePath);
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
this.log('goint to use keypair of', this._keypair.getPublicKey().toSuiAddress());
|
|
@@ -51,7 +54,7 @@ class SuiMaster extends SuiCommonMethods {
|
|
|
51
54
|
if (params.provider) {
|
|
52
55
|
if (params.provider == 'local' || (params.provider.constructor && params.provider.constructor.name && params.provider.constructor.name == 'SuiLocalTestValidator')) {
|
|
53
56
|
if (params.provider == 'local') {
|
|
54
|
-
this._provider = new
|
|
57
|
+
this._provider = new SuiClient({url: getFullnodeUrl('localnet')});
|
|
55
58
|
this._providerName = 'sui:localnet';
|
|
56
59
|
} else {
|
|
57
60
|
// SuiLocalTestValidator
|
|
@@ -61,18 +64,34 @@ class SuiMaster extends SuiCommonMethods {
|
|
|
61
64
|
// this._provider = new sui.JsonRpcProvider(sui.localnetConnection);
|
|
62
65
|
// this._providerName = 'sui:localnet';
|
|
63
66
|
} else if (params.provider == 'test' || params.provider == 'testnet') {
|
|
64
|
-
this._provider = new
|
|
67
|
+
this._provider = new SuiClient({url: getFullnodeUrl('testnet')});
|
|
65
68
|
this._providerName = 'sui:testnet';
|
|
66
69
|
} else if (params.provider == 'dev' || params.provider == 'devnet') {
|
|
67
|
-
this._provider = new
|
|
70
|
+
this._provider = new SuiClient({url: getFullnodeUrl('devnet')});
|
|
68
71
|
this._providerName = 'sui:devnet';
|
|
69
72
|
} else if (params.provider == 'main' || params.provider == 'mainnet') {
|
|
70
|
-
this._provider = new
|
|
73
|
+
this._provider = new SuiClient({url: getFullnodeUrl('mainnet')});
|
|
71
74
|
this._providerName = 'sui:mainnet';
|
|
72
75
|
|
|
73
76
|
this.log('we are on the mainnet, working with real money, be careful');
|
|
74
77
|
} else {
|
|
75
|
-
if (params.provider && params.provider.
|
|
78
|
+
if (params.provider && params.provider.constructor && params.provider.constructor.name && params.provider.constructor.name == 'SuiClient') {
|
|
79
|
+
this._provider = params.provider;
|
|
80
|
+
const url = params.provider.transport.websocketClient.endpoint;
|
|
81
|
+
|
|
82
|
+
if (url.indexOf('devnet') !== -1) {
|
|
83
|
+
this._providerName = 'sui:devnet';
|
|
84
|
+
} else if (url.indexOf('testnet') !== -1) {
|
|
85
|
+
this._providerName = 'sui:testnet';
|
|
86
|
+
} else if (url.indexOf('mainnet') !== -1) {
|
|
87
|
+
this._providerName = 'sui:mainnet';
|
|
88
|
+
} else if (url.indexOf('127.0.0.1') !== -1) {
|
|
89
|
+
this._providerName = 'sui:localnet';
|
|
90
|
+
} else {
|
|
91
|
+
// just keep provider name as unique to fullnode URL to keep separate ObjectStorage instances
|
|
92
|
+
this._providerName = url.split('//')[1];
|
|
93
|
+
}
|
|
94
|
+
} else if (params.provider && params.provider.connection && params.provider.connection.fullnode) {
|
|
76
95
|
this._provider = params.provider;
|
|
77
96
|
|
|
78
97
|
if (params.provider.connection.fullnode.indexOf('devnet') !== -1) {
|
|
@@ -116,7 +135,7 @@ class SuiMaster extends SuiCommonMethods {
|
|
|
116
135
|
}
|
|
117
136
|
|
|
118
137
|
get MIST_PER_SUI() {
|
|
119
|
-
return BigInt(
|
|
138
|
+
return BigInt(MIST_PER_SUI);
|
|
120
139
|
}
|
|
121
140
|
|
|
122
141
|
/**
|
|
@@ -201,13 +220,20 @@ class SuiMaster extends SuiCommonMethods {
|
|
|
201
220
|
|
|
202
221
|
// this._keypair = sui.Ed25519Keypair.deriveKeypair(this._phrase);
|
|
203
222
|
if (!this._signer && this._keypair) { // we may optionally go without signer, to work in read-only mode
|
|
204
|
-
this._signer = new sui.RawSigner(this._keypair, this._provider);
|
|
223
|
+
this._signer = this._keypair;//new sui.RawSigner(this._keypair, this._provider);
|
|
205
224
|
}
|
|
206
225
|
|
|
207
226
|
// const publicKey = this._keypair.getPublicKey();
|
|
208
227
|
// this._address = publicKey.toSuiAddress();
|
|
209
228
|
if (this._signer) {
|
|
210
|
-
|
|
229
|
+
if (this._signer.toSuiAddress) {
|
|
230
|
+
this._address = this._signer.toSuiAddress(); // after Sui's refactor Keypair's method
|
|
231
|
+
} else if (this._signer.connectedAddress) {
|
|
232
|
+
this._address = this._signer.connectedAddress;
|
|
233
|
+
} else {
|
|
234
|
+
this._address = await this._signer.getAddress(); // old method
|
|
235
|
+
}
|
|
236
|
+
|
|
211
237
|
// console.log(this._signer);
|
|
212
238
|
// console.log(this._providerName);
|
|
213
239
|
this.log('initialized. connected as', this._address);
|
|
@@ -219,24 +245,31 @@ class SuiMaster extends SuiCommonMethods {
|
|
|
219
245
|
return true;
|
|
220
246
|
}
|
|
221
247
|
|
|
248
|
+
async signAndExecuteTransactionBlock(params) {
|
|
249
|
+
if (this._keypair) {
|
|
250
|
+
params.signer = this._keypair;
|
|
251
|
+
return this._provider.signAndExecuteTransactionBlock(params);
|
|
252
|
+
} else if (this._signer) {
|
|
253
|
+
return this._signer.signAndExecuteTransactionBlock(params);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
222
257
|
async requestSuiFromFaucet() {
|
|
223
258
|
await this.initialize();
|
|
224
259
|
|
|
225
260
|
this.log('requesting sui from faucet...');
|
|
226
261
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
res = null;
|
|
233
|
-
}
|
|
262
|
+
const faucetHost = getFaucetHost(this._providerName.split('sui:').join(''));
|
|
263
|
+
const requested = await requestSuiFromFaucetV0({
|
|
264
|
+
host: faucetHost,
|
|
265
|
+
recipient: this._address,
|
|
266
|
+
});
|
|
234
267
|
|
|
235
268
|
let amount = BigInt(0);
|
|
236
269
|
let objectsCount = 0;
|
|
237
270
|
|
|
238
|
-
if (
|
|
239
|
-
for (let transferredGasObject of
|
|
271
|
+
if (requested && requested.transferredGasObjects) {
|
|
272
|
+
for (let transferredGasObject of requested.transferredGasObjects) {
|
|
240
273
|
amount += BigInt(transferredGasObject.amount);
|
|
241
274
|
objectsCount++;
|
|
242
275
|
}
|
|
@@ -353,6 +386,6 @@ class SuiMaster extends SuiCommonMethods {
|
|
|
353
386
|
|
|
354
387
|
};
|
|
355
388
|
|
|
356
|
-
SuiMaster.MIST_PER_SUI = BigInt(
|
|
389
|
+
SuiMaster.MIST_PER_SUI = BigInt(MIST_PER_SUI);
|
|
357
390
|
|
|
358
391
|
module.exports = SuiMaster;
|
package/lib/SuiObject.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const sui = require('@mysten/sui.js');
|
|
2
1
|
const SuiCommonMethods = require('./SuiCommonMethods.js');
|
|
3
2
|
const SuiPaginatedResponse = require('./SuiPaginatedResponse.js');
|
|
3
|
+
const { normalizeSuiAddress } = require('@mysten/sui.js/utils');
|
|
4
4
|
|
|
5
5
|
class SuiObject extends SuiCommonMethods {
|
|
6
6
|
constructor(params = {}) {
|
|
@@ -41,7 +41,7 @@ class SuiObject extends SuiCommonMethods {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
static idsEqual(id1, id2) {
|
|
44
|
-
return (
|
|
44
|
+
return (normalizeSuiAddress(id1) === normalizeSuiAddress(id2));
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
get isDeleted() {
|
|
@@ -94,7 +94,7 @@ class SuiObject extends SuiCommonMethods {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
const thisAddress = this.address;
|
|
97
|
-
if (thisAddress && thisAddress ===
|
|
97
|
+
if (thisAddress && thisAddress === normalizeSuiAddress(toId)) {
|
|
98
98
|
return true;
|
|
99
99
|
}
|
|
100
100
|
return false;
|
|
@@ -102,7 +102,7 @@ class SuiObject extends SuiCommonMethods {
|
|
|
102
102
|
|
|
103
103
|
get address() {
|
|
104
104
|
try {
|
|
105
|
-
return
|
|
105
|
+
return normalizeSuiAddress(this._id);
|
|
106
106
|
} catch (e) {
|
|
107
107
|
return null;
|
|
108
108
|
}
|
package/lib/SuiPackage.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const sui = require('@mysten/sui.js');
|
|
2
|
-
|
|
3
1
|
const SuiCliCommands = require('./SuiCliCommands.js');
|
|
4
2
|
const SuiObject = require('./SuiObject.js');
|
|
5
3
|
const SuiPackageModule = require('./SuiPackageModule.js');
|
|
6
4
|
const SuiPaginatedResponse = require('./SuiPaginatedResponse.js');
|
|
7
5
|
|
|
8
6
|
// fromB64, toB64
|
|
7
|
+
const { TransactionBlock } = require('@mysten/sui.js/transactions');
|
|
8
|
+
const { normalizeSuiAddress } = require('@mysten/sui.js/utils');
|
|
9
9
|
|
|
10
10
|
class SuiPackage extends SuiObject {
|
|
11
11
|
constructor(params = {}) {
|
|
@@ -345,7 +345,7 @@ class SuiPackage extends SuiObject {
|
|
|
345
345
|
if (result && result.objectChanges && result.objectChanges.length) {
|
|
346
346
|
for (const objectChange of result.objectChanges) {
|
|
347
347
|
if (objectChange.type === 'published' && objectChange.packageId) {
|
|
348
|
-
this._id =
|
|
348
|
+
this._id = normalizeSuiAddress(objectChange.packageId);
|
|
349
349
|
this._isPublished = true;
|
|
350
350
|
|
|
351
351
|
if (objectChange.version) {
|
|
@@ -398,7 +398,7 @@ class SuiPackage extends SuiObject {
|
|
|
398
398
|
|
|
399
399
|
this.log('publishing package...');
|
|
400
400
|
|
|
401
|
-
const tx = new
|
|
401
|
+
const tx = new TransactionBlock();
|
|
402
402
|
const [upgradeCap] = tx.publish({
|
|
403
403
|
modules: this._builtModules,
|
|
404
404
|
dependencies: this._builtDependencies,
|
|
@@ -406,7 +406,7 @@ class SuiPackage extends SuiObject {
|
|
|
406
406
|
|
|
407
407
|
tx.transferObjects([upgradeCap], tx.pure(this._suiMaster.address));
|
|
408
408
|
|
|
409
|
-
const result = await this._suiMaster.
|
|
409
|
+
const result = await this._suiMaster.signAndExecuteTransactionBlock({
|
|
410
410
|
transactionBlock: tx,
|
|
411
411
|
requestType: 'WaitForLocalExecution',
|
|
412
412
|
options: {
|
|
@@ -434,7 +434,7 @@ class SuiPackage extends SuiObject {
|
|
|
434
434
|
|
|
435
435
|
this.log('upgrading package...');
|
|
436
436
|
|
|
437
|
-
const tx = new
|
|
437
|
+
const tx = new TransactionBlock();
|
|
438
438
|
|
|
439
439
|
const cap = tx.object(await this.getUpgradeCapId());
|
|
440
440
|
// export enum UpgradePolicy {
|
|
@@ -461,7 +461,7 @@ class SuiPackage extends SuiObject {
|
|
|
461
461
|
arguments: [cap, receipt],
|
|
462
462
|
});
|
|
463
463
|
|
|
464
|
-
const result = await this._suiMaster.
|
|
464
|
+
const result = await this._suiMaster.signAndExecuteTransactionBlock({
|
|
465
465
|
transactionBlock: tx,
|
|
466
466
|
options: {
|
|
467
467
|
showEffects: true,
|
package/lib/SuiPackageModule.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const sui = require('@mysten/sui.js');
|
|
2
1
|
const SuiObject = require('./SuiObject.js');
|
|
3
2
|
|
|
4
3
|
const SuiCommonMethods = require('./SuiCommonMethods.js');
|
|
@@ -6,6 +5,9 @@ const SuiPaginatedResponse = require('./SuiPaginatedResponse.js');
|
|
|
6
5
|
const SuiEvent = require('./SuiEvent.js');
|
|
7
6
|
// fromB64, toB64
|
|
8
7
|
|
|
8
|
+
const { TransactionBlock } = require('@mysten/sui.js/transactions');
|
|
9
|
+
const { normalizeSuiAddress } = require('@mysten/sui.js/utils');
|
|
10
|
+
|
|
9
11
|
class SuiPackageModule extends SuiCommonMethods {
|
|
10
12
|
constructor(params = {}) {
|
|
11
13
|
super(params);
|
|
@@ -88,7 +90,7 @@ class SuiPackageModule extends SuiCommonMethods {
|
|
|
88
90
|
address = suiObjectOrAddress.address;
|
|
89
91
|
}
|
|
90
92
|
try {
|
|
91
|
-
address =
|
|
93
|
+
address = normalizeSuiAddress(address);
|
|
92
94
|
if (!this.objectStorage.byAddress(address)) {
|
|
93
95
|
if (suiObjectOrAddress.address) {
|
|
94
96
|
// instance of suiObject
|
|
@@ -119,7 +121,7 @@ class SuiPackageModule extends SuiCommonMethods {
|
|
|
119
121
|
if (params.tx) {
|
|
120
122
|
tx = params.tx;
|
|
121
123
|
} else {
|
|
122
|
-
tx = new
|
|
124
|
+
tx = new TransactionBlock();
|
|
123
125
|
|
|
124
126
|
const callArgs = [];
|
|
125
127
|
|
|
@@ -150,7 +152,7 @@ class SuiPackageModule extends SuiCommonMethods {
|
|
|
150
152
|
});
|
|
151
153
|
}
|
|
152
154
|
|
|
153
|
-
const result = await this._suiMaster.
|
|
155
|
+
const result = await this._suiMaster.signAndExecuteTransactionBlock({
|
|
154
156
|
transactionBlock: tx,
|
|
155
157
|
requestType: 'WaitForLocalExecution',
|
|
156
158
|
options: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { entropyToMnemonic } = require('@scure/bip39');
|
|
2
2
|
const { wordlist } = require('@scure/bip39/wordlists/english');
|
|
3
|
-
const { Ed25519Keypair } = require('@mysten/sui.js');
|
|
3
|
+
const { Ed25519Keypair } = require('@mysten/sui.js/keypairs/ed25519');
|
|
4
4
|
|
|
5
5
|
class SuiPseudoRandomAddress {
|
|
6
6
|
static stringToKeyPair(as) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suidouble",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47",
|
|
4
4
|
"description": "Set of provider, package and object classes for javascript representation of Sui Move smart contracts. Use same code for publishing, upgrading, integration testing, interaction with smart contracts and integration in browser web3 dapps",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const t = require('tap');
|
|
4
|
+
const { test } = t;
|
|
5
|
+
|
|
6
|
+
const { SuiMaster, SuiLocalTestValidator, TransactionBlock } = require('..');
|
|
7
|
+
|
|
8
|
+
let suiLocalTestValidator = null;
|
|
9
|
+
let suiMaster = null;
|
|
10
|
+
|
|
11
|
+
test('spawn local test node', async t => {
|
|
12
|
+
suiLocalTestValidator = await SuiLocalTestValidator.launch({ testFallbackEnabled: true });
|
|
13
|
+
t.ok(suiLocalTestValidator.active);
|
|
14
|
+
|
|
15
|
+
// SuiLocalTestValidator runs as signle instance. So you can't start it twice with static method
|
|
16
|
+
const suiLocalTestValidatorCopy = await SuiLocalTestValidator.launch();
|
|
17
|
+
t.equal(suiLocalTestValidator, suiLocalTestValidatorCopy);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('init suiMaster and connect it to local test validator', async t => {
|
|
21
|
+
suiMaster = new SuiMaster({provider: 'local', as: 'somebody', debug: true});
|
|
22
|
+
await suiMaster.initialize();
|
|
23
|
+
|
|
24
|
+
t.ok(suiMaster.address); // there should be some address
|
|
25
|
+
t.ok(`${suiMaster.address}`.indexOf('0x') === 0); // adress is string starting with '0x'
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('type is normalized for SUI', async t => {
|
|
29
|
+
// eveything should be the same:
|
|
30
|
+
const suiCoin1 = suiMaster.suiCoins.get('sui');
|
|
31
|
+
const suiCoin2 = suiMaster.suiCoins.get('SUI');
|
|
32
|
+
const suiCoin3 = suiMaster.suiCoins.get('0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI');
|
|
33
|
+
const suiCoin4 = suiMaster.suiCoins.get('0x2::sui::SUI');
|
|
34
|
+
const suiCoin5 = suiMaster.suiCoins.get('2::sui::SUI');
|
|
35
|
+
const suiCoin6 = suiMaster.suiCoins.get('0000000000000000000000000000000000000000000000000000000000000002::sui::SUI');
|
|
36
|
+
|
|
37
|
+
t.ok(suiCoin1.coinType == suiCoin2.coinType);
|
|
38
|
+
t.ok(suiCoin1.coinType == suiCoin3.coinType);
|
|
39
|
+
t.ok(suiCoin1.coinType == suiCoin4.coinType);
|
|
40
|
+
t.ok(suiCoin1.coinType == suiCoin5.coinType);
|
|
41
|
+
t.ok(suiCoin1.coinType == suiCoin6.coinType);
|
|
42
|
+
|
|
43
|
+
// moreover, it should be the same instance
|
|
44
|
+
t.ok(Object.keys(suiMaster.suiCoins.coins).length == 1);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('amount normalization works ok', async t => {
|
|
48
|
+
const suiCoin = suiMaster.suiCoins.get('sui');
|
|
49
|
+
t.ok((await suiCoin.lazyNormalizeAmount('1.0')) == suiMaster.MIST_PER_SUI); // lazy - loads metadata to get decimals
|
|
50
|
+
t.ok((await suiCoin.lazyNormalizeAmount(suiMaster.MIST_PER_SUI)) == suiMaster.MIST_PER_SUI); // can pass BigInt
|
|
51
|
+
t.ok((await suiCoin.lazyNormalizeAmount(Number(suiMaster.MIST_PER_SUI))) == suiMaster.MIST_PER_SUI); // can pass Number, it will return BigInt of if
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('string representation works ok', async t => {
|
|
55
|
+
const suiCoin = suiMaster.suiCoins.get('sui');
|
|
56
|
+
await suiCoin.getMetadata();
|
|
57
|
+
|
|
58
|
+
const toDisplay1 = suiCoin.amountToString(suiMaster.MIST_PER_SUI);
|
|
59
|
+
t.equals(toDisplay1, '1.0');
|
|
60
|
+
|
|
61
|
+
const toDisplay2 = suiCoin.amountToString(1); // 1 mist
|
|
62
|
+
t.equals(toDisplay2, '0.000000001');
|
|
63
|
+
|
|
64
|
+
const toDisplay3 = suiCoin.amountToString(suiMaster.MIST_PER_SUI * BigInt(1000) + BigInt(1)); // 1000 SUI + 1 mist
|
|
65
|
+
t.equals(toDisplay3, '1000.000000001');
|
|
66
|
+
|
|
67
|
+
const toDisplay4 = suiCoin.amountToString(suiMaster.MIST_PER_SUI * BigInt(1000) - BigInt(1)); // 1000 SUI - 1 mist
|
|
68
|
+
t.equals(toDisplay4, '999.999999999');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('you have no SUI on the fresh node', async t => {
|
|
72
|
+
const suiCoin = suiMaster.suiCoins.get('sui');
|
|
73
|
+
const balance = await suiCoin.getBalance(suiMaster.address);
|
|
74
|
+
t.ok(balance == BigInt(0));
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('have some after requesting from faucet', async t => {
|
|
78
|
+
await suiMaster.requestSuiFromFaucet();
|
|
79
|
+
|
|
80
|
+
const suiCoin = suiMaster.suiCoins.get('sui');
|
|
81
|
+
const balance = await suiCoin.getBalance(suiMaster.address);
|
|
82
|
+
t.ok(balance > BigInt(0));
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('getting coin objects for a transaction', async t => {
|
|
86
|
+
const suiCoin = suiMaster.suiCoins.get('sui');
|
|
87
|
+
|
|
88
|
+
const wasBalance = await suiCoin.getBalance(suiMaster.address);
|
|
89
|
+
|
|
90
|
+
const txb = new TransactionBlock();
|
|
91
|
+
const coinInput = await suiCoin.coinOfAmountToTxCoin(txb, suiMaster.address, suiMaster.MIST_PER_SUI); // pick 1 SUI
|
|
92
|
+
txb.transferObjects([coinInput], txb.pure('0x1d20dcdb2bca4f508ea9613994683eb4e76e9c4ed371169677c1be02aaf0b12a')); // send it anywhere
|
|
93
|
+
|
|
94
|
+
const result = await suiMaster.signAndExecuteTransactionBlock({
|
|
95
|
+
transactionBlock: txb,
|
|
96
|
+
requestType: 'WaitForLocalExecution',
|
|
97
|
+
options: {
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const nowBalance = await suiCoin.getBalance(suiMaster.address);
|
|
102
|
+
|
|
103
|
+
t.ok(nowBalance < wasBalance); /// would be better to calculate everthing + fees + storage rebate, but let's just assume it works for now.
|
|
104
|
+
// @todo : cover better
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
test('stops local test node', async t => {
|
|
110
|
+
await SuiLocalTestValidator.stop();
|
|
111
|
+
});
|