suidouble 1.0.4-7 → 1.0.5
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/README.md
CHANGED
|
@@ -168,7 +168,9 @@ while (events.hasNextPage) {
|
|
|
168
168
|
|
|
169
169
|
##### subscribing to events
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
*** Subscribe to Events is deprecated in Sui SDK *** You should plan to use different architecture in your application.
|
|
172
|
+
|
|
173
|
+
You can subscribe to Sui's contract events on package's module level.
|
|
172
174
|
|
|
173
175
|
```javascript
|
|
174
176
|
const module = await contract.getModule('suidouble_chat');
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
const net = require("net");
|
|
2
2
|
const SuiCliCommands = require('./SuiCliCommands.js');
|
|
3
3
|
const SuiCommonMethods = require('./SuiCommonMethods.js');
|
|
4
|
-
// const { JsonRpcProvider, localnetConnection, devnetConnection } = require('@mysten/sui.js');
|
|
5
4
|
|
|
6
5
|
const { SuiClient, getFullnodeUrl, SuiHTTPTransport } = require('@mysten/sui/client');
|
|
7
6
|
const SuiUtils = require('./SuiUtils.js');
|
|
@@ -65,6 +64,51 @@ class SuiLocalTestValidator extends SuiCommonMethods {
|
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
66
|
|
|
67
|
+
async isPortThere(port) {
|
|
68
|
+
const Socket = net.Socket;
|
|
69
|
+
const socket = new Socket();
|
|
70
|
+
|
|
71
|
+
let __waitPortPromiseResolver = null;
|
|
72
|
+
const __waitPortPromise = new Promise((res)=>{ __waitPortPromiseResolver = res; });
|
|
73
|
+
|
|
74
|
+
setTimeout(()=>{
|
|
75
|
+
socket.destroy();
|
|
76
|
+
__waitPortPromiseResolver(false);
|
|
77
|
+
}, 3000);
|
|
78
|
+
socket.on("connect", () => {
|
|
79
|
+
__waitPortPromiseResolver(true);
|
|
80
|
+
});
|
|
81
|
+
socket.on("error", () =>
|
|
82
|
+
{
|
|
83
|
+
__waitPortPromiseResolver(false);
|
|
84
|
+
});
|
|
85
|
+
socket.on("timeout", () => {
|
|
86
|
+
__waitPortPromiseResolver(false);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
socket.connect(port, "0.0.0.0");
|
|
90
|
+
|
|
91
|
+
const portIsThere = await __waitPortPromise;
|
|
92
|
+
socket.destroy();
|
|
93
|
+
|
|
94
|
+
return portIsThere;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async waitForPort(port, timeout) {
|
|
98
|
+
this.log('waiting for port', port);
|
|
99
|
+
const startedCheckingAt = (new Date()).getTime();
|
|
100
|
+
let portIsThere = false;
|
|
101
|
+
do {
|
|
102
|
+
portIsThere = await this.isPortThere(port);
|
|
103
|
+
this.log('checking for port', port, 'is there:', portIsThere);
|
|
104
|
+
if (!portIsThere) {
|
|
105
|
+
await new Promise((res)=>setTimeout(res, 500));
|
|
106
|
+
}
|
|
107
|
+
} while (!portIsThere && (startedCheckingAt + timeout) > ((new Date()).getTime()));
|
|
108
|
+
|
|
109
|
+
return portIsThere;
|
|
110
|
+
}
|
|
111
|
+
|
|
68
112
|
async launch() {
|
|
69
113
|
if (this._active) {
|
|
70
114
|
return this;
|
|
@@ -73,12 +117,22 @@ class SuiLocalTestValidator extends SuiCommonMethods {
|
|
|
73
117
|
this.log('launching sui-test-validator ...');
|
|
74
118
|
|
|
75
119
|
try {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
params
|
|
79
|
-
|
|
120
|
+
try {
|
|
121
|
+
// try sui-test-validator
|
|
122
|
+
const params = [];
|
|
123
|
+
if (this._epochDuration) {
|
|
124
|
+
params.push('--epoch-duration-ms');
|
|
125
|
+
params.push(this._epochDuration);
|
|
126
|
+
}
|
|
127
|
+
this._child = await SuiCliCommands.spawn('sui-test-validator', params, { RUST_LOG: 'consensus=off' });
|
|
128
|
+
} catch (e) {
|
|
129
|
+
this.log('can not launch sui-test-validator. Trying to run "sui start"...');
|
|
130
|
+
const params = [];
|
|
131
|
+
params.push('start');
|
|
132
|
+
params.push('--with-faucet');
|
|
133
|
+
params.push('--force-regenesis');
|
|
134
|
+
this._child = await SuiCliCommands.spawn('sui', params, { RUST_LOG: 'off,sui_node=info' });
|
|
80
135
|
}
|
|
81
|
-
this._child = await SuiCliCommands.spawn('sui-test-validator', params, { RUST_LOG: 'consensus=off' });
|
|
82
136
|
} catch (e) {
|
|
83
137
|
if (this._testFallbackEnabled) {
|
|
84
138
|
// can't start local node. Let's switch to sui:dev
|
|
@@ -93,29 +147,6 @@ class SuiLocalTestValidator extends SuiCommonMethods {
|
|
|
93
147
|
throw e;
|
|
94
148
|
}
|
|
95
149
|
}
|
|
96
|
-
|
|
97
|
-
this.__readyLaunchedPromiseResolver = null;
|
|
98
|
-
this.__readyLaunchedPromise = new Promise((res)=>{
|
|
99
|
-
this.__readyLaunchedPromiseResolver = res;
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
this._child.stdout.on('data', (data) => {
|
|
103
|
-
this.log(`stdout:\n${data}`);
|
|
104
|
-
if ((`${data}`).indexOf('Fullnode RPC URL') !== -1) {
|
|
105
|
-
this._active = true;
|
|
106
|
-
|
|
107
|
-
this.log('sui-test-validator launched');
|
|
108
|
-
this.__readyLaunchedPromiseResolver();
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
this._child.stderr.on('data', (data) => {
|
|
113
|
-
this.log(`stderr: ${data}`);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
this._child.on('error', (error) => {
|
|
117
|
-
this.log(`error: ${error.message}`);
|
|
118
|
-
});
|
|
119
150
|
|
|
120
151
|
this._child.on('close', (code) => {
|
|
121
152
|
this._active = false;
|
|
@@ -131,7 +162,9 @@ class SuiLocalTestValidator extends SuiCommonMethods {
|
|
|
131
162
|
process.on('SIGINT', cleanExit); // catch ctrl-c
|
|
132
163
|
process.on('SIGTERM', cleanExit); // catch kill
|
|
133
164
|
|
|
134
|
-
await this.
|
|
165
|
+
this._active = await this.waitForPort(9123, 30000);
|
|
166
|
+
|
|
167
|
+
// await this.__readyLaunchedPromise;
|
|
135
168
|
|
|
136
169
|
return this;
|
|
137
170
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suidouble",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
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": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"author": "Jeka Kiselyov <jeka911@gmail.com> (https://github.com/jeka-kiselyov)",
|
|
22
22
|
"license": "Apache-2.0",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@mysten/sui": "
|
|
24
|
+
"@mysten/sui": "1.0.5",
|
|
25
25
|
"@wallet-standard/core": "^1.0.3",
|
|
26
26
|
"websocket": "^1.0.35"
|
|
27
27
|
},
|
|
@@ -152,33 +152,36 @@ test('can find a package on the blockchain by expected module name (in owned)',
|
|
|
152
152
|
t.equal(contract.version, 2);
|
|
153
153
|
});
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
// Event websocket subscriptions are going to be deprecated.
|
|
156
|
+
// test('subscribe to module events', async t => {
|
|
157
|
+
// const module = await contract.getModule('suidouble_chat');
|
|
158
|
+
// await module.subscribeEvents();
|
|
158
159
|
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
// let gotEventChatTopMessageCreated = false;
|
|
161
|
+
// let gotEventChatResponseCreated = false;
|
|
161
162
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
163
|
+
// module.addEventListener('ChatTopMessageCreated', (event)=>{
|
|
164
|
+
// gotEventChatTopMessageCreated = event;
|
|
165
|
+
// });
|
|
166
|
+
// module.addEventListener('ChatResponseCreated', (event)=>{
|
|
167
|
+
// gotEventChatResponseCreated = event.detail; // .detail is reference to event itself. To support CustomEvent pattern
|
|
168
|
+
// });
|
|
168
169
|
|
|
169
|
-
|
|
170
|
-
|
|
170
|
+
// await contract.moveCall('suidouble_chat', 'post', [chatShopObjectId, contract.arg('string', 'the message'), contract.arg('string', 'metadata')]);
|
|
171
|
+
// await new Promise((res)=>setTimeout(res, 300)); // got events without timeout, but just to be sure.
|
|
171
172
|
|
|
172
|
-
|
|
173
|
-
|
|
173
|
+
// t.ok(gotEventChatTopMessageCreated);
|
|
174
|
+
// t.ok(gotEventChatResponseCreated);
|
|
174
175
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
// // just some checks that events have data by contract's architecture
|
|
177
|
+
// t.ok(gotEventChatResponseCreated.parsedJson.top_message_id == gotEventChatTopMessageCreated.parsedJson.id);
|
|
178
|
+
// t.ok(gotEventChatTopMessageCreated.parsedJson.top_response_id == gotEventChatResponseCreated.parsedJson.id);
|
|
178
179
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
// // unsubscribing from events, to close websocket
|
|
181
|
+
// await module.unsubscribeEvents();
|
|
182
|
+
|
|
183
|
+
// t.end();
|
|
184
|
+
// });
|
|
182
185
|
|
|
183
186
|
test('execute contract methods', async t => {
|
|
184
187
|
const moveCallResult = await contract.moveCall('suidouble_chat', 'post', [chatShopObjectId, contract.arg('string', 'the message'), contract.arg('string', 'metadata')]);
|