suidouble 0.0.6 → 0.0.8
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 +2 -0
- package/lib/SuiLocalTestValidator.js +5 -8
- package/lib/SuiMaster.js +21 -5
- package/package.json +18 -4
- package/test/sui_master_basic.test.js +62 -0
- package/test/sui_master_onlocal.test.js +39 -0
package/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const SuiMaster = require('./lib/SuiMaster.js');
|
|
2
2
|
const SuiInBrowser = require('./lib/SuiInBrowser.js');
|
|
3
3
|
const SuiTestScenario = require('./lib/SuiTestScenario.js');
|
|
4
|
+
const SuiLocalTestValidator = require('./lib/SuiLocalTestValidator.js');
|
|
4
5
|
|
|
5
6
|
module.exports = {
|
|
6
7
|
SuiMaster,
|
|
7
8
|
SuiInBrowser,
|
|
8
9
|
SuiTestScenario,
|
|
10
|
+
SuiLocalTestValidator,
|
|
9
11
|
};
|
|
@@ -10,6 +10,10 @@ class SuiLocalTestValidator extends SuiCommonMethods {
|
|
|
10
10
|
this._active = false;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
get active() {
|
|
14
|
+
return this._active;
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
static async launch(params = {}) {
|
|
14
18
|
if (SuiLocalTestValidator.__instance) {
|
|
15
19
|
return await SuiLocalTestValidator.__instance.launch();
|
|
@@ -27,19 +31,12 @@ class SuiLocalTestValidator extends SuiCommonMethods {
|
|
|
27
31
|
|
|
28
32
|
async launch() {
|
|
29
33
|
if (this._child && this._active) {
|
|
30
|
-
return
|
|
34
|
+
return this;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
this.log('launching sui-test-validator ...');
|
|
34
38
|
|
|
35
39
|
this._child = await SuiCliCommands.spawn('sui-test-validator', { RUST_LOG: 'consensus=off' });
|
|
36
|
-
|
|
37
|
-
// spawn('sui-test-validator', [], {
|
|
38
|
-
// env: {
|
|
39
|
-
// ...process.env,
|
|
40
|
-
// RUST_LOG: 'consensus=off',
|
|
41
|
-
// }
|
|
42
|
-
// });
|
|
43
40
|
|
|
44
41
|
this.__readyLaunchedPromiseResolver = null;
|
|
45
42
|
this.__readyLaunchedPromise = new Promise((res)=>{
|
package/lib/SuiMaster.js
CHANGED
|
@@ -35,22 +35,34 @@ class SuiMaster extends SuiCommonMethods {
|
|
|
35
35
|
if (params.provider) {
|
|
36
36
|
if (params.provider == 'local' || (params.provider.constructor && params.provider.constructor.name && params.provider.constructor.name == 'SuiLocalTestValidator')) {
|
|
37
37
|
this._provider = new sui.JsonRpcProvider(sui.localnetConnection);
|
|
38
|
-
this._providerName = '
|
|
38
|
+
this._providerName = 'sui:localnet';
|
|
39
39
|
} else if (params.provider == 'test' || params.provider == 'testnet') {
|
|
40
40
|
this._provider = new sui.JsonRpcProvider(sui.testnetConnection);
|
|
41
|
-
this._providerName = '
|
|
41
|
+
this._providerName = 'sui:testnet';
|
|
42
42
|
} else if (params.provider == 'dev' || params.provider == 'devnet') {
|
|
43
43
|
this._provider = new sui.JsonRpcProvider(sui.devnetConnection);
|
|
44
|
-
this._providerName = '
|
|
44
|
+
this._providerName = 'sui:devnet';
|
|
45
45
|
} else if (params.provider == 'main' || params.provider == 'mainnet') {
|
|
46
46
|
this._provider = new sui.JsonRpcProvider(sui.mainnetConnection);
|
|
47
|
-
this._providerName = '
|
|
47
|
+
this._providerName = 'sui:mainnet';
|
|
48
48
|
|
|
49
49
|
this.log('we are on the mainnet, working with real money, be careful');
|
|
50
50
|
} else {
|
|
51
51
|
if (params.provider && params.provider.connection && params.provider.connection.fullnode) {
|
|
52
52
|
this._provider = params.provider;
|
|
53
|
-
|
|
53
|
+
|
|
54
|
+
if (params.provider.connection.fullnode.indexOf('devnet') !== -1) {
|
|
55
|
+
this._providerName = 'sui:devnet';
|
|
56
|
+
} else if (params.provider.connection.fullnode.indexOf('testnet') !== -1) {
|
|
57
|
+
this._providerName = 'sui:testnet';
|
|
58
|
+
} else if (params.provider.connection.fullnode.indexOf('mainnet') !== -1) {
|
|
59
|
+
this._providerName = 'sui:mainnet';
|
|
60
|
+
} else if (params.provider.connection.fullnode.indexOf('127.0.0.1') !== -1) {
|
|
61
|
+
this._providerName = 'sui:localnet';
|
|
62
|
+
} else {
|
|
63
|
+
// just keep provider name as unique to fullnode URL to keep separate ObjectStorage instances
|
|
64
|
+
this._providerName = params.provider.connection.fullnode;
|
|
65
|
+
}
|
|
54
66
|
}
|
|
55
67
|
}
|
|
56
68
|
}
|
|
@@ -85,6 +97,10 @@ class SuiMaster extends SuiCommonMethods {
|
|
|
85
97
|
return this._provider;
|
|
86
98
|
}
|
|
87
99
|
|
|
100
|
+
get connectedChain() {
|
|
101
|
+
return this._providerName;
|
|
102
|
+
}
|
|
103
|
+
|
|
88
104
|
get address() {
|
|
89
105
|
return this._address;
|
|
90
106
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suidouble",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
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": {
|
|
7
|
-
"test": "
|
|
7
|
+
"test": "tap -j=1 ./test/*.test.js",
|
|
8
|
+
"coverage": "tap -j=1 ./test/*.test.js"
|
|
8
9
|
},
|
|
9
|
-
"keywords": [
|
|
10
|
+
"keywords": [
|
|
11
|
+
"sui",
|
|
12
|
+
"sui move",
|
|
13
|
+
"move",
|
|
14
|
+
"smart contract",
|
|
15
|
+
"smart contracts",
|
|
16
|
+
"sui.js",
|
|
17
|
+
"web3",
|
|
18
|
+
"dapps",
|
|
19
|
+
"dapp"
|
|
20
|
+
],
|
|
10
21
|
"author": "Jeka Kiselyov <jeka911@gmail.com> (https://github.com/jeka-kiselyov)",
|
|
11
22
|
"license": "Apache-2.0",
|
|
12
23
|
"dependencies": {
|
|
13
24
|
"@mysten/sui.js": "^0.34.0",
|
|
14
25
|
"@wallet-standard/core": "^1.0.3"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"tap": "^16.3.4"
|
|
15
29
|
}
|
|
16
|
-
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const t = require('tap');
|
|
4
|
+
const { test } = t;
|
|
5
|
+
|
|
6
|
+
const { SuiMaster } = require('..');
|
|
7
|
+
|
|
8
|
+
test('initialization', async t => {
|
|
9
|
+
t.plan(2);
|
|
10
|
+
|
|
11
|
+
t.ok(true);
|
|
12
|
+
t.equal(1, 1, 'Ready state is (==1)');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('pseudo-random keypairs generation works ok', async t => {
|
|
16
|
+
const suiMaster = new SuiMaster({provider: 'test', as: 'somebody'});
|
|
17
|
+
await suiMaster.initialize();
|
|
18
|
+
|
|
19
|
+
// pseudo-random generation of 'somebody' is a keypair for a wallet '0x15b9493fb639a3118fed766ca80c1da62fa20493c293f319cc7d136506d2db69'
|
|
20
|
+
// not sure if we need to assert it, as we may change pseudo-random generation algo, still keeping it function,
|
|
21
|
+
// so lets just check we make different keypairs depending on 'as' input parameter
|
|
22
|
+
// console.log(suiMaster.address);
|
|
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
|
+
const suiMasterAsAdmin = new SuiMaster({provider: 'test', as: 'admin'});
|
|
28
|
+
await suiMasterAsAdmin.initialize();
|
|
29
|
+
|
|
30
|
+
t.ok(suiMasterAsAdmin.address); // there should be some address
|
|
31
|
+
t.ok(`${suiMasterAsAdmin.address}`.indexOf('0x') === 0); // adress is string starting with '0x'
|
|
32
|
+
|
|
33
|
+
t.not(`${suiMaster.address}`, `${suiMasterAsAdmin.address}`, 'different pseudo randoms should be different');
|
|
34
|
+
|
|
35
|
+
/// but if you pass the same string as 'as' - it will generate the same keypair:
|
|
36
|
+
const suiMasterAsAdminAnother = new SuiMaster({provider: 'test', as: 'admin'});
|
|
37
|
+
await suiMasterAsAdminAnother.initialize();
|
|
38
|
+
|
|
39
|
+
t.equal(`${suiMasterAsAdminAnother.address}`, `${suiMasterAsAdmin.address}`, 'same string should generate same pseudo-random');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('connecting to different chains', async t => {
|
|
43
|
+
const suiMaster = new SuiMaster({provider: 'test', as: 'somebody'});
|
|
44
|
+
await suiMaster.initialize();
|
|
45
|
+
|
|
46
|
+
t.equal(suiMaster.connectedChain, 'sui:testnet');
|
|
47
|
+
|
|
48
|
+
const suiMaster2 = new SuiMaster({provider: 'dev', as: 'somebody'});
|
|
49
|
+
await suiMaster2.initialize();
|
|
50
|
+
|
|
51
|
+
t.equal(suiMaster2.connectedChain, 'sui:devnet');
|
|
52
|
+
|
|
53
|
+
const suiMaster3 = new SuiMaster({provider: 'main', as: 'somebody'});
|
|
54
|
+
await suiMaster3.initialize();
|
|
55
|
+
|
|
56
|
+
t.equal(suiMaster3.connectedChain, 'sui:mainnet');
|
|
57
|
+
|
|
58
|
+
const suiMaster4 = new SuiMaster({provider: 'local', as: 'somebody'});
|
|
59
|
+
await suiMaster4.initialize();
|
|
60
|
+
|
|
61
|
+
t.equal(suiMaster4.connectedChain, 'sui:localnet');
|
|
62
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const t = require('tap');
|
|
4
|
+
const { test } = t;
|
|
5
|
+
|
|
6
|
+
const { SuiMaster, SuiLocalTestValidator } = require('..');
|
|
7
|
+
|
|
8
|
+
let suiLocalTestValidator = null;
|
|
9
|
+
let suiMaster = null;
|
|
10
|
+
|
|
11
|
+
test('spawn local test node', async t => {
|
|
12
|
+
suiLocalTestValidator = await SuiLocalTestValidator.launch();
|
|
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: suiLocalTestValidator, as: 'somebody'});
|
|
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('request sui from faucet', async t => {
|
|
29
|
+
const balanceBefore = await suiMaster.getBalance();
|
|
30
|
+
await suiMaster.requestSuiFromFaucet();
|
|
31
|
+
|
|
32
|
+
const balanceAfter = await suiMaster.getBalance();
|
|
33
|
+
|
|
34
|
+
t.ok(balanceAfter > balanceBefore);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('stops local test node', async t => {
|
|
38
|
+
SuiLocalTestValidator.stop();
|
|
39
|
+
});
|