suidouble 0.0.9 → 0.0.11

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/lib/SuiObject.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const sui = require('@mysten/sui.js');
2
2
  const SuiCommonMethods = require('./SuiCommonMethods.js');
3
+ const SuiPaginatedResponse = require('./SuiPaginatedResponse.js');
3
4
 
4
5
  class SuiObject extends SuiCommonMethods {
5
6
  constructor(params = {}) {
@@ -119,19 +120,23 @@ class SuiObject extends SuiCommonMethods {
119
120
  return this._localProperties;
120
121
  }
121
122
 
122
- async getDynamicFields() {
123
- const result = await this._suiMaster._provider.getDynamicFields({
124
- parentId: this.address, // normalized id
125
- options: {
126
- showType: true,
127
- showContent: true,
128
- showOwner: true,
129
- showDisplay: true,
130
- "showPreviousTransaction": true,
131
- "showBcs": false,
132
- "showStorageRebate": true
133
- },
123
+ async getDynamicFields(params = {}) {
124
+ const queryParams = {
125
+ parentId: this.address,
126
+ limit: params.limit || 50,
127
+ };
128
+
129
+ const paginatedResponse = new SuiPaginatedResponse({
130
+ debug: this._debug,
131
+ suiMaster: this._suiMaster,
132
+ params: queryParams,
133
+ method: 'getDynamicFields',
134
+ order: params.order,
134
135
  });
136
+
137
+ await paginatedResponse.fetch();
138
+
139
+ return paginatedResponse;
135
140
  }
136
141
 
137
142
  async fetchFields() {
@@ -21,6 +21,10 @@ class SuiTestScenario extends SuiCommonMethods {
21
21
  this._publishedPackageId = null;
22
22
  }
23
23
 
24
+ get currentAs() {
25
+ return this._currentAs;
26
+ }
27
+
24
28
  /**
25
29
  * Start local test validator and set up `as` as owner of package deploy transaction.
26
30
  * Package will be deployed with method `init`, as we try to mimic Sui Move's test_scenario
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suidouble",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
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": {
@@ -187,6 +187,11 @@ test('execute contract methods', async t => {
187
187
  const chatTopMessage = contract.objectStorage.findMostRecentByTypeName('ChatTopMessage');
188
188
  t.ok(chatTopMessage);
189
189
 
190
+ const dynamicFields = await chatTopMessage.getDynamicFields();
191
+ // as per sample move contract design, after the thread posted, chatResponse is attached to chatTopMessage as a dynamic object field
192
+ // it's there till the very first response to thread is posted
193
+ t.ok(dynamicFields.data.length === 1);
194
+
190
195
  const responseTextAsBytes = [].slice.call(new TextEncoder().encode('ขอบคุณครับ, 🇺🇦')); // regular array with utf data
191
196
  const moveCallResult2 = await contract.moveCall('suidouble_chat', 'reply', [chatTopMessage.id, responseTextAsBytes, 'metadata']);
192
197
 
@@ -0,0 +1,57 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap');
4
+ const { test } = t;
5
+ const path = require('path');
6
+
7
+ const { SuiTestScenario } = require('..');
8
+
9
+ let testScenario = null;
10
+
11
+ test('initialization', async t => {
12
+ testScenario = new SuiTestScenario({
13
+ path: path.join(__dirname, './test_move_contracts/suidouble_chat/'),
14
+ debug: false,
15
+ });
16
+
17
+ await testScenario.begin('admin');
18
+ await testScenario.init();
19
+
20
+ t.equal(testScenario.currentAs, 'admin');
21
+ });
22
+
23
+ test('checking takeShared', async t => {
24
+ t.plan(4);
25
+
26
+ await testScenario.nextTx('admin', async()=>{
27
+ const chatShop = testScenario.takeShared('ChatShop');
28
+
29
+ t.ok(chatShop.address); // there should be some address
30
+ t.ok(`${chatShop.address}`.indexOf('0x') === 0); // adress is string starting with '0x'
31
+
32
+ await testScenario.moveCall('suidouble_chat', 'post', [chatShop.address, 'posting a message', 'metadata']);
33
+ const chatTopMessage = testScenario.takeShared('ChatTopMessage');
34
+
35
+ t.ok(chatTopMessage.address); // there should be some address
36
+ t.ok(`${chatTopMessage.address}`.indexOf('0x') === 0); // adress is string starting with '0x'
37
+ });
38
+ });
39
+
40
+ test('checking takeOwned', async t => {
41
+ t.plan(3);
42
+
43
+ await testScenario.nextTx('somebody', async()=>{
44
+ const chatTopMessage = testScenario.takeShared('ChatTopMessage');
45
+ t.ok(chatTopMessage.address); // there should be some address
46
+
47
+ await testScenario.moveCall('suidouble_chat', 'reply', [chatTopMessage.address, 'posting a response', 'metadata']);
48
+ const chatResponse = testScenario.takeFromSender('ChatResponse');
49
+
50
+ t.ok(chatResponse.address); // there should be some address
51
+ t.ok(`${chatResponse.address}`.indexOf('0x') === 0); // adress is string starting with '0x'
52
+ });
53
+ })
54
+
55
+ test('finishing the test scenario', async t => {
56
+ await testScenario.end();
57
+ });