How to use getTableRows method in Cucumber-gherkin

Best JavaScript code snippet using cucumber-gherkin

Run Cucumber-gherkin automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

wax-unit.test.js

Source: wax-unit.test.js Github

copy
1const {
2  setupTestChain,
3  randomWamAccount,
4  createAccount,
5  setContract,
6  updateAuth,
7  linkauth,
8  eosjs,
9  transfer,
10  TESTING_PUBLIC_KEY,
11  getTableRows,
12  genericAction,
13  dedupeTapos,
14  addTime,
15} = require('../');
16
17describe('wax-unit', () => {
18  let myContract;
19  beforeAll(async () => {
20    await setupTestChain(); // Must be called first to setup the test chain
21
22    await createAccount('mycontract11');
23
24    myContract = await setContract(
25      'mycontract11',
26      'tests/test-contract/build/testcontract.wasm',
27      'tests/test-contract/build/testcontract.abi'
28    );
29    await updateAuth('mycontract11', `active`, `owner`, {
30      threshold: 1,
31      accounts: [
32        {
33          permission: {
34            actor: 'mycontract11',
35            permission: `eosio.code`,
36          },
37          weight: 1,
38        },
39      ],
40      keys: [
41        {
42          key: TESTING_PUBLIC_KEY,
43          weight: 1,
44        },
45      ],
46      waits: [],
47    });
48
49    await transfer(
50      'eosio',
51      'mycontract11',
52      '200.00000000 WAX',
53      `sending some test funds`
54    );
55  });
56
57  it('should init table data', async () => {
58    await myContract.loadTable('entries', {
59      [myContract.account]: [
60        {
61          id: 1,
62          entry_time: '2022-02-24T22:27:57',
63        },
64        {
65          id: 2,
66          entry_time: '2022-03-25T22:28:58',
67        },
68      ],
69    });
70    const entries = await getTableRows(
71      myContract.account,
72      `entries`,
73      myContract.account
74    );
75    expect(entries.length).toEqual(2);
76    expect(entries[0].id).toEqual(1);
77    expect(entries[0].entry_time).toEqual('2022-02-24T22:27:57');
78  });
79
80  it('should init table data from json file', async () => {
81    await myContract.loadTableFromFile('entries', 'tests/entries.json');
82    const entries = await getTableRows(
83      myContract.account,
84      `entries`,
85      'loadfile1111'
86    );
87    expect(entries.length).toEqual(3);
88    expect(entries[0].id).toEqual(1);
89    expect(entries[0].entry_time).toEqual('2022-02-24T22:26:56');
90  });
91
92  it('should call addentry action', async () => {
93    await myContract.call(
94      'addentry',
95      [
96        {
97          actor: myContract.account,
98          permission: 'active',
99        },
100      ],
101      {
102        id: 3,
103      }
104    );
105    const entries = await getTableRows(
106      myContract.account,
107      `entries`,
108      myContract.account
109    );
110    expect(entries.length).toEqual(3);
111    expect(entries[2].id).toEqual(3);
112  });
113
114  it('can read table data', async () => {
115    const balances = await getTableRows(
116      'eosio.token',
117      `accounts`,
118      'mycontract11'
119    );
120    expect(balances.length).toEqual(1);
121    expect(balances[0].balance).toEqual('200.00000000 WAX');
122  });
123
124  describe('addTime', () => {
125    it('standard path', async () => {
126      const entriesInitial = await getTableRows(
127        'mycontract11',
128        `entries`,
129        'mycontract11'
130      );
131      const id = 4;
132
133      // add new entry
134      const res = await genericAction(
135        'mycontract11',
136        'addentry',
137        {
138          id,
139        },
140        [
141          {
142            actor: 'mycontract11',
143            permission: 'active',
144          },
145        ]
146      );
147
148      let entries = await getTableRows(
149        'mycontract11',
150        `entries`,
151        'mycontract11'
152      );
153
154      expect(entries.length).toBe(entriesInitial.length + 1);
155      expect(entries[entriesInitial.length].id).toBe(id);
156
157      await expect(
158        genericAction(
159          'mycontract11',
160          'expireentry',
161          {
162            id,
163            expiry_seconds: 600,
164          },
165          [
166            {
167              actor: 'mycontract11',
168              permission: 'active',
169            },
170          ]
171        )
172      ).rejects.toThrow('Entry not expired yet');
173
174      await addTime(601, res.processed.block_time);
175
176      await genericAction(
177        'mycontract11',
178        'expireentry',
179        {
180          id,
181          expiry_seconds: 600,
182        },
183        [
184          {
185            actor: 'mycontract11',
186            permission: 'active',
187          },
188        ]
189      );
190
191      entries = await getTableRows('mycontract11', `entries`, 'mycontract11');
192
193      expect(entries.length).toBe(entriesInitial.length);
194    });
195
196    it('can add multiple times', async () => {
197      const entriesInitial = await getTableRows(
198        'mycontract11',
199        `entries`,
200        'mycontract11'
201      );
202      const id = 5;
203
204      // add new entry
205      const res = await genericAction(
206        'mycontract11',
207        'addentry',
208        {
209          id,
210        },
211        [
212          {
213            actor: 'mycontract11',
214            permission: 'active',
215          },
216        ]
217      );
218
219      let entries = await getTableRows(
220        'mycontract11',
221        `entries`,
222        'mycontract11'
223      );
224
225      expect(entries.length).toBe(entriesInitial.length + 1);
226      expect(entries[entriesInitial.length].id).toBe(id);
227
228      await expect(
229        genericAction(
230          'mycontract11',
231          'expireentry',
232          {
233            id,
234            expiry_seconds: 600,
235          },
236          [
237            {
238              actor: 'mycontract11',
239              permission: 'active',
240            },
241          ]
242        )
243      ).rejects.toThrow('Entry not expired yet');
244
245      await addTime(300, res.processed.block_time);
246
247      await expect(
248        genericAction(
249          'mycontract11',
250          'expireentry',
251          {
252            id,
253            expiry_seconds: 600,
254          },
255          [
256            {
257              actor: 'mycontract11',
258              permission: 'active',
259            },
260          ]
261        )
262      ).rejects.toThrow('Entry not expired yet');
263
264      await addTime(301);
265
266      await genericAction(
267        'mycontract11',
268        'expireentry',
269        {
270          id,
271          expiry_seconds: 600,
272        },
273        [
274          {
275            actor: 'mycontract11',
276            permission: 'active',
277          },
278        ]
279      );
280
281      entries = await getTableRows('mycontract11', `entries`, 'mycontract11');
282
283      expect(entries.length).toBe(entriesInitial.length);
284    });
285
286    it('can add far into the future', async () => {
287      const entriesInitial = await getTableRows(
288        'mycontract11',
289        `entries`,
290        'mycontract11'
291      );
292      const id = 6;
293
294      // add new entry
295      const res = await genericAction(
296        'mycontract11',
297        'addentry',
298        {
299          id,
300        },
301        [
302          {
303            actor: 'mycontract11',
304            permission: 'active',
305          },
306        ]
307      );
308
309      let entries = await getTableRows(
310        'mycontract11',
311        `entries`,
312        'mycontract11'
313      );
314
315      expect(entries.length).toBe(entriesInitial.length + 1);
316      expect(entries[entriesInitial.length].id).toBe(id);
317
318      await expect(
319        genericAction(
320          'mycontract11',
321          'expireentry',
322          {
323            id,
324            expiry_seconds: 600,
325          },
326          [
327            {
328              actor: 'mycontract11',
329              permission: 'active',
330            },
331          ]
332        )
333      ).rejects.toThrow('Entry not expired yet');
334
335      await addTime(600001, res.processed.block_time);
336
337      await genericAction(
338        'mycontract11',
339        'expireentry',
340        {
341          id,
342          expiry_seconds: 600,
343        },
344        [
345          {
346            actor: 'mycontract11',
347            permission: 'active',
348          },
349        ]
350      );
351
352      entries = await getTableRows('mycontract11', `entries`, 'mycontract11');
353
354      expect(entries.length).toBe(entriesInitial.length);
355    });
356  });
357});
358
Full Screen

script.js

Source: script.js Github

copy
1//Title constructor function that creates a Title object
2function Title(t1) 
3{ 
4  this.mytitle = t1;
5}
6
7Title.prototype.getName = function () 
8{ 
9return (this.mytitle);
10}
11
12var socialMedia = {
13  facebook : 'http://facebook.com',
14  twitter: 'http://twitter.com',
15  flickr: 'http://flickr.com',
16  youtube: 'http://youtube.com'
17};
18
19window.onload = function () {
20  var dropDown = document.getElementsByClassName('dropDownTextArea');
21  for (var i = 0; i < dropDown.length; i++) {
22    dropDown[i].style.display = 'none';
23  }
24
25  document.getElementById('button').disabled = true;
26  document.getElementById('button').style.backgroundColor = 'gray';
27  document.getElementById('button').style.color = 'white';
28  document.getElementById('button').style.border = '1px solid gray';
29
30   var getTableRows = document.getElementById('myTable').getElementsByTagName('tr');
31   for (var rowObject = 0; rowObject < getTableRows.length; rowObject++) {
32     for (var columnNumber = 0; columnNumber < getTableRows[rowObject].cells.length; columnNumber++){
33       if(columnNumber == 8){
34         getTableRows[rowObject].cells[8].style.visibility='hidden';
35       }
36     }
37  }
38}
39
40function toggle(getImage) {
41  var imageId = getImage.id.slice(5);//1
42  imageId = imageId-1;
43  var dropDown = document.getElementsByClassName('dropDownTextArea');//3
44  
45  for (var ddNumber = 0; ddNumber < dropDown.length; ddNumber++) {// 0 to 2
46    if (ddNumber == imageId) {
47      if (dropDown[ddNumber].style.display == 'none') {
48        dropDown[ddNumber].style.display = 'contents';
49      } else {
50        dropDown[ddNumber].style.display = 'none';
51      }
52    }
53  }
54}
55
56function addRow() {
57  // Getting tbody of the table 
58  var tableRef = document.getElementById('myTable').getElementsByTagName('tbody')[0];
59
60  // Adding row in tbody 
61  var count = tableRef.rows.length;
62  count = count - 1;
63  var newRow   = tableRef.insertRow(count);
64  count = count-1;
65    var newCell;
66    var newText;
67
68
69    newCell  = newRow.insertCell(0);
70    // newText  = document.createTextNode('Student '+ count);
71    // newCell.appendChild(newText);
72
73    var addCheckbox = document.createElement('input');
74    addCheckbox.type = 'checkbox';
75    addCheckbox.id = count.toString();
76    newCell.appendChild(addCheckbox);
77    addCheckbox.onclick = function () {
78      getCheckBoxValue();
79    }
80
81    newText  = document.createElement("br");
82    newCell.appendChild(newText);
83
84    newText  = document.createElement("br");
85    newCell.appendChild(newText);
86
87    var addImage = document.createElement('img');
88    addImage.src = 'down.png';
89    addImage.id= 'img'+ count.toString();
90    addImage.style.display = 'block';
91    addImage.style.width = '25px';
92    newCell.appendChild(addImage);
93    addImage.onclick = function () {
94      toggle(addImage.this);
95    }
96
97    newCell  = newRow.insertCell(1);
98    newText  = document.createTextNode('Student '+ count);
99    newCell.appendChild(newText);
100    
101    newCell  = newRow.insertCell(2);
102    newText  = document.createTextNode('Teacher '+ count);
103    newCell.appendChild(newText);
104
105    newCell  = newRow.insertCell(3);
106    newText  = document.createTextNode('Approved');
107    newCell.appendChild(newText);
108
109    newCell  = newRow.insertCell(4);
110    newText  = document.createTextNode('Fall');
111    newCell.appendChild(newText);
112
113    newCell  = newRow.insertCell(5);
114    newText  = document.createTextNode('TA');
115    newCell.appendChild(newText);
116
117    newCell  = newRow.insertCell(6);
118    var num = Math.floor(Math.random() * 90000);
119    newText  = document.createTextNode(num.toString());
120    newCell.appendChild(newText);
121
122    newCell  = newRow.insertCell(7);
123    num = Math.floor(Math.random() * 100);
124    newText  = document.createTextNode(num.toString() + "%" );
125    newCell.appendChild(newText);
126
127    newCell  = newRow.insertCell(8);
128    newText  = document.createTextNode('');
129    newCell.appendChild(newText);
130    newCell.style.visibility='hidden';
131}
132
133function getCheckBoxValue(){
134  var getTableRows = document.getElementById('myTable').getElementsByTagName('tr');
135  var getCheckBox = document.getElementById('myTable').getElementsByTagName('input');
136
137  getTableRows[0].cells[getTableRows[0].cells.length - 1].style.visibility = 'visible';
138
139  var getCheckBox1 = document.getElementById('myTable').getElementsByTagName('input');
140  for (var checkBoxNumber1 = 0; checkBoxNumber1 < getCheckBox1.length; checkBoxNumber1++) {
141    if(!getCheckBox1[checkBoxNumber1].checked){
142      getTableRows[0].cells[getTableRows[0].cells.length - 1].style.visibility = 'hidden';
143      document.getElementById('button').disabled = true;
144      document.getElementById('button').style.backgroundColor = 'gray';
145      document.getElementById('button').style.color = 'white';
146      document.getElementById('button').style.border = '1px solid gray';
147    }
148  }
149  
150  for (var checkBoxNumber = 0; checkBoxNumber < getCheckBox.length; checkBoxNumber++) {
151    if (getCheckBox[checkBoxNumber].checked) {
152      
153      getCheckBox[checkBoxNumber].parentElement.parentElement.style.backgroundColor = "orange";
154      document.getElementById('button').disabled = false;
155      document.getElementById('button').style.backgroundColor = 'orange';
156      document.getElementById('button').style.border = '1px solid orange';
157
158      var getTableRows = document.getElementById('myTable').getElementsByTagName('tr');
159      getTableRows[0].cells[8].style.visibility='visible';
160
161      var getRow = getCheckBox[checkBoxNumber].parentNode.parentNode;
162      getRow.cells[getRow.cells.length - 1].style.visibility = 'visible';
163      // document.getElementById('button').style.backgroundColor = 'orange';
164      
165
166      if (!document.getElementById('delete' + checkBoxNumber)) {
167        var createBtn = document.createElement('button');
168        var createBtnName = document.createTextNode('Delete');
169        createBtn.id = 'delete' + checkBoxNumber;
170        createBtn.appendChild(createBtnName);
171      
172        getRow.cells[getRow.cells.length - 1].style.visibility = 'visible';
173        getRow.cells[getRow.cells.length - 1].appendChild(createBtn);
174        createBtn.onclick = function () {
175            removeRow(this);
176        }
177      }
178      
179    }
180    else{
181      getCheckBox[checkBoxNumber].parentElement.parentElement.style.backgroundColor = "white";
182
183      var getRow = getCheckBox[checkBoxNumber].parentNode.parentNode;
184      getRow.cells[getRow.cells.length - 1].style.visibility = 'hidden';
185
186      if (document.getElementById('delete' + checkBoxNumber)) {
187        document.getElementById('delete' + checkBoxNumber).remove();
188      }
189    }
190  }  
191}
192
193function removeRow(getRow) {
194  getRow.parentNode.parentNode.remove();
195  var getTableRows = document.getElementById('myTable').getElementsByTagName('tr');
196
197  var getCheckBox1 = document.getElementById('myTable').getElementsByTagName('input');
198  for (var checkBoxNumber1 = 0; checkBoxNumber1 < getCheckBox1.length; checkBoxNumber1++) {
199    if(!getCheckBox1[checkBoxNumber1].checked){
200      getTableRows[0].cells[getTableRows[0].cells.length - 1].style.visibility = 'hidden';
201      document.getElementById('button').disabled = true;
202      document.getElementById('button').style.backgroundColor = 'gray';
203      document.getElementById('button').style.color = 'white';
204      document.getElementById('button').style.border = '1px solid gray';
205    }
206  }
207
208}
Full Screen

eosapi.js

Source: eosapi.js Github

copy
1import { bidnameContract, newBidnameContract } from "@/common/data"
2
3export const apiGetTokenAccountRows = (eosApi) => {
4  let params = {
5    json: true,
6    code: "aidosonecoin",
7    table: "accounts",
8    lower_bound: "",
9    upper_bound: "",
10    limit: 100
11  }
12
13  return eosApi.getTableRows(params)
14}
15
16export const apiGetProfitsRows = (eosApi, account) => {
17  let params = {
18    json: true,
19    code: "huskeyrecord",
20    scope: "huskeyrecord",
21    table: "profits",
22    lower_bound: account,
23    upper_bound: account,
24    limit: 1
25  }
26
27  return eosApi.getTableRows(params)
28}
29
30export const apiGetDelBandwidthRows = (eosApi, account, limit) => {
31  let params = {
32    json: true,
33    code: "eosio",
34    scope: account,
35    table: "delband",
36    limit: limit,
37    lower_bound: 0,
38    uppper_bound: -1
39  }
40
41  return eosApi.getTableRows(params)
42}
43
44export const apiGetRexfundsRows = (eosApi, account) => {
45  let params = {
46    json: true,
47    code: "eosio",
48    scope: account,
49    table: "refunds",
50    limit: 10,
51    lower_bound: 0,
52    uppper_bound: -1
53  }
54
55  return eosApi.getTableRows(params)
56}
57
58export const apiGetRexOrderRows = (eosApi, account, limit) => {
59  let params = {
60    json: true,
61    code: "eosio",
62    scope: "eosio",
63    table: "rexbal",
64    lower_bound: account,
65    upper_bound: null,
66    index_position: 1,
67    key_type: "i64",
68    limit: 1
69  }
70
71  return eosApi.getTableRows(params)
72}
73
74export const apiGetRexPoolRows = (eosApi) => {
75  let params = {
76    json: true,
77    code: "eosio",
78    scope: "eosio",
79    table: "rexpool",
80    table_key: "",
81    lower_bound: "",
82    upper_bound: "",
83    limit: 1
84  }
85
86  return eosApi.getTableRows(params)
87}
88
89export const apiGetRexfundRows = (eosApi, account) => {
90  let params = {
91    json: true,
92    code: "eosio",
93    scope: "eosio",
94    table: "rexfund",
95    table_key: "",
96    lower_bound: account,
97    upper_bound: "",
98    limit: 1
99  }
100
101  return eosApi.getTableRows(params)
102}
103
104export const apiGetNamebidsRows = (eosApi) => {
105  let params = {
106    json: true,
107    code: "eosio",
108    scope: "eosio",
109    table: "namebids",
110    table_key: null,
111    lower_bound: null,
112    upper_bound: null,
113    key_type: "i64",
114    index_position: 2,
115    limit: 50
116  }
117
118  return eosApi.getTableRows(params)
119}
120
121export const apiSearchBidRows = (newname, eosApi) => {
122  let params = {
123    json: true,
124    code: "eosio",
125    scope: "eosio",
126    table: "namebids",
127    table_key: null,
128    upper_bound: newname,
129    lower_bound: newname,
130    key_type: "i64",
131    index_position: 1,
132    limit: 1
133  }
134
135  return eosApi.getTableRows(params)
136}
137
138export const apiGetBidSuccessRows = (eosApi) => {
139  let params = {
140    json: true,
141    code: bidnameContract,
142    scope: bidnameContract,
143    table: "bidsuccess",
144    table_key: null,
145    lower_bound: null,
146    upper_bound: null,
147    key_type: "i64",
148    index_position: 2,
149    limit: 50
150  }
151
152  return eosApi.getTableRows(params)
153}
154
155export const apiGetBidOrderRows = (scope,eosApi) => {
156  let params = {
157    json: true,
158    code: bidnameContract,
159    scope: scope,
160    table: "bidorders",
161    table_key: null,
162    lower_bound: null,
163    upper_bound: null,
164    key_type: "i64",
165    index_position: 2,
166    limit: 50
167  }
168
169  return eosApi.getTableRows(params)
170}
171
172export const apiGetNewBidnameRows = (scope, eosApi) => {
173  let params = {
174    json: true,
175    code: newBidnameContract,
176    scope: scope,
177    table: "namebids",
178    table_key: null,
179    upper_bound: null,
180    lower_bound: null,
181    key_type: "i64",
182    index_position: 2,
183    limit: 100
184  }
185
186  return eosApi.getTableRows(params)
187}
188
189export const apiSearchNewBidnameRows = (newname, scope, eosApi) => {
190  let params = {
191    json: true,
192    code: newBidnameContract,
193    scope: scope,
194    table: "namebids",
195    table_key: null,
196    upper_bound: newname,
197    lower_bound: newname,
198    key_type: "i64",
199    index_position: 1,
200    limit: 1
201  }
202
203  return eosApi.getTableRows(params)
204}
205
206export const apiGetNewBidRewardsRows = (newname, eosApi) => {
207  let params = {
208    json: true,
209    code: newBidnameContract,
210    scope: newname,
211    table: "bidrewards",
212    table_key: null,
213    lower_bound: null,
214    upper_bound: null,
215    key_type: "i64",
216    index_position: 2,
217    limit: 200
218  }
219
220  return eosApi.getTableRows(params)
221}
222
223export const apiGetNewBidSuccessRows = (eosApi) => {
224  let params = {
225    json: true,
226    code: newBidnameContract,
227    scope: newBidnameContract,
228    table: "bidsuccess",
229    table_key: null,
230    lower_bound: null,
231    upper_bound: null,
232    key_type: "i64",
233    index_position: 2,
234    limit: 50
235  }
236
237  return eosApi.getTableRows(params)
238}
239
240export const apiGetNewBidOrderRows = (scope, eosApi) => {
241  let params = {
242    json: true,
243    code: newBidnameContract,
244    scope: scope,
245    table: "bidorders",
246    table_key: null,
247    lower_bound: null,
248    upper_bound: null,
249    key_type: "i64",
250    index_position: 2,
251    limit: 50
252  }
253
254  return eosApi.getTableRows(params)
255}
256
257export const apiGetNewBidNameInfoRows = (eosApi) => {
258  let params = {
259    json: true,
260    code: newBidnameContract,
261    scope: newBidnameContract,
262    table: "nameinfos",
263    table_key: null,
264    lower_bound: null,
265    upper_bound: null,
266    limit: 50
267  }
268
269  return eosApi.getTableRows(params)
270}
271
272/*export const apiGetYASSalesRows = (eosApi) => {
273  let params = {
274    json: true,
275    code: newBidnameContract,
276    scope: newBidnameContract,
277    table: "bidname11",
278    table_key: null,
279    upper_bound: null,
280    lower_bound: null,
281    key_type: "i64",
282    index_position: 2,
283    limit: 100
284  }
285
286  return eosApi.getTableRows(params)
287}
288
289export const apiGetIBTSalesRows = (eosApi) => {
290  let params = {
291    json: true,
292    code: newBidnameContract,
293    scope: newBidnameContract,
294    table: "bidname22",
295    table_key: null,
296    upper_bound: null,
297    lower_bound: null,
298    key_type: "i64",
299    index_position: 2,
300    limit: 100
301  }
302
303  return eosApi.getTableRows(params)
304}
305
306export const apiSearchIBTSalesRows = (newname, eosApi) => {
307  let params = {
308    json: true,
309    code: newBidnameContract,
310    scope: newBidnameContract,
311    table: "bidname22",
312    table_key: null,
313    upper_bound: newname,
314    lower_bound: newname,
315    key_type: "i64",
316    index_position: 1,
317    limit: 1
318  }
319
320  return eosApi.getTableRows(params)
321}
322
323export const apiSearchYASSalesRows = (newname, eosApi) => {
324  let params = {
325    json: true,
326    code: newBidnameContract,
327    scope: newBidnameContract,
328    table: "bidname11",
329    table_key: null,
330    upper_bound: newname,
331    lower_bound: newname,
332    key_type: "i64",
333    index_position: 1,
334    limit: 1
335  }
336
337  return eosApi.getTableRows(params)
338}
339
340export const apiGetNamedexRewardsRows = (newname, eosApi) => {
341  let params = {
342    json: true,
343    code: newBidnameContract,
344    scope: newname,
345    table: "bidrewards",
346    table_key: null,
347    lower_bound: null,
348    upper_bound: null,
349    key_type: "i64",
350    index_position: 2,
351    limit: 200
352  }
353
354  return eosApi.getTableRows(params)
355}*/
356
357export const apiGetBidsTopRows = (eosApi) => {
358  let params = {
359    json: true,
360    code: bidnameContract,
361    scope: bidnameContract,
362    table: "namebids1",
363    table_key: null,
364    upper_bound: null,
365    lower_bound: null,
366    key_type: "i64",
367    index_position: 2,
368    limit: 100
369  }
370
371  return eosApi.getTableRows(params)
372}
373
374export const apiSearchBidTopRows = (newname, eosApi) => {
375  let params = {
376    json: true,
377    code: bidnameContract,
378    scope: bidnameContract,
379    table: "namebids1",
380    table_key: null,
381    upper_bound: newname,
382    lower_bound: newname,
383    key_type: "i64",
384    index_position: 1,
385    limit: 1
386  }
387
388  return eosApi.getTableRows(params)
389}
390
391export const apiGetBidsBetRows = (eosApi) => {
392  let params = {
393    json: true,
394    code: bidnameContract,
395    scope: bidnameContract,
396    table: "namebids2",
397    table_key: null,
398    upper_bound: null,
399    lower_bound: null,
400    key_type: "i64",
401    index_position: 2,
402    limit: 500
403  }
404
405  return eosApi.getTableRows(params)
406}
407
408export const apiSearchBidBetRows = (newname, eosApi) => {
409  let params = {
410    json: true,
411    code: bidnameContract,
412    scope: bidnameContract,
413    table: "namebids2",
414    table_key: null,
415    upper_bound: newname,
416    lower_bound: newname,
417    key_type: "i64",
418    index_position: 1,
419    limit: 1
420  }
421
422  return eosApi.getTableRows(params)
423}
424
425export const apiGetBidrewardsRows = (newname, eosApi) => {
426  let params = {
427    json: true,
428    code: bidnameContract,
429    scope: newname,
430    table: "bidrewards",
431    table_key: null,
432    lower_bound: null,
433    upper_bound: null,
434    key_type: "i64",
435    index_position: 2,
436    limit: 200
437  }
438
439  return eosApi.getTableRows(params)
440}
441
442export const apiGetSalePriceRows = (eosApi) => {
443  let params = {
444    json: true,
445    code: bidnameContract,
446    scope: bidnameContract,
447    table: "saleprices",
448    table_key: null,
449    lower_bound: null,
450    upper_bound: null,
451    key_type: "i64",
452    index_position: 1,
453    limit: 100
454  }
455
456  return eosApi.getTableRows(params)
457}
458
459export const apiDelegatebw = (api, authorization, data) => {
460  let action = {
461    account: "eosio",
462    name: "delegatebw",
463    authorization: [authorization],
464    data: {
465      from: data.from,
466      receiver: data.receiver,
467      stake_cpu_quantity: data.stake_cpu_quantity,
468      stake_net_quantity: data.stake_net_quantity,
469      transfer: false
470    }
471  }
472  
473  return api.transact({ 
474    actions: [action] 
475  },{
476    blocksBehind: 3,
477    expireSeconds: 30
478  })
479}
480
481export const apiUnDelegatebw = (api, authorization, data) => {
482  let action = {
483    account: "eosio",
484    name: "undelegatebw",
485    authorization: [authorization],
486    data: {
487      from: data.from,
488      receiver: data.receiver,
489      unstake_net_quantity: data.unstake_net_quantity,
490      unstake_cpu_quantity: data.unstake_cpu_quantity,
491    }
492  }
493
494  return api.transact({
495    actions: [action]
496  }, {
497    blocksBehind: 3,
498    expireSeconds: 30
499  })
500}
501
502export const apiBuyRex = (api, authorization, buyAccount, buyRexNum, voteData) => {
503  let actions = []
504  if (voteData) {
505    actions.push({
506      account: "eosio",
507      name: "voteproducer",
508      authorization: [authorization],
509      data: {
510        voter: buyAccount,
511        proxy: voteData.proxy,
512        producers: voteData.producers
513      }
514    })
515  }
516  actions.push({
517    account: "eosio",
518    name: "deposit",
519    authorization: [authorization],
520    data: {
521      owner: buyAccount,
522      amount: Number(buyRexNum).toFixed(4) + " YAS"
523    }
524  })
525  actions.push({
526    account: "eosio",
527    name: "buyrex",
528    authorization: [authorization],
529    data: {
530      from: buyAccount,
531      amount: Number(buyRexNum).toFixed(4) + " YAS"
532    }
533  })
534
535  return api.transact({
536    actions: actions
537  }, {
538    blocksBehind: 3,
539    expireSeconds: 30
540  })
541}
542
543export const apiSellRex = (api, authorization, sellAccount, sellRex) => {
544  let actions = []
545  actions.push({
546    account: "eosio",
547    name: "sellrex",
548    authorization: [authorization],
549    data: {
550      from: sellAccount,
551      rex: Number(sellRex).toFixed(4) + " REX"
552    }
553  })
554
555  return api.transact({
556    actions: actions
557  }, {
558    blocksBehind: 3,
559    expireSeconds: 30
560  })
561}
562
563export const apiDelegateToRex = (api, authorization, owner, reciveAccount, fromCPU, fromNET, voteData) => {
564  let actions = []
565  if (voteData) {
566    actions.push({
567      account: "eosio",
568      name: "voteproducer",
569      authorization: [authorization],
570      data: {
571        voter: reciveAccount,
572        proxy: voteData.proxy,
573        producers: voteData.producers
574      }
575    })
576  }
577
578  actions.push({
579    account: "eosio",
580    name: "unstaketorex",
581    authorization: [authorization],
582    data: {
583      owner: owner,
584      receiver: reciveAccount, 
585      from_net: Number(fromNET).toFixed(4) + " YAS", 
586      from_cpu: Number(fromCPU).toFixed(4) + " YAS", 
587    }
588  })
589
590  return api.transact({
591    actions: actions
592  }, {
593    blocksBehind: 3,
594    expireSeconds: 30
595  })
596}
597
598export const apiRexWithdraw = (api, authorization, account, amount) => {
599  let actions = []
600  actions.push({
601    account: "eosio",
602    name: "withdraw",
603    authorization: [authorization],
604    data: {
605      owner: account,
606      amount: Number(amount).toFixed(4) + " YAS"
607    }
608  })
609
610  return api.transact({
611    actions: actions
612  }, {
613    blocksBehind: 3,
614    expireSeconds: 30
615  })
616}
617
618export const apiBuyRam = (api, authorization, data) => {
619  let actions = []
620  actions.push({
621    account: "eosio",
622    name: "buyram",
623    authorization: [authorization],
624    data: data
625  })
626
627  return api.transact({
628    actions: actions
629  }, {
630    blocksBehind: 3,
631    expireSeconds: 30
632  })
633}
634
635export const apiSellRam = (api, authorization, data) => {
636  let actions = []
637  actions.push({
638    account: "eosio",
639    name: "sellram",
640    authorization: [authorization],
641    data: data
642  })
643
644  return api.transact({
645    actions: actions
646  }, {
647    blocksBehind: 3,
648    expireSeconds: 30
649  })
650} 
651
652export const apiRentCpu = (api, authorization, buyAccount, reciveAccount, buyAmount) => {
653  let actions = []
654  let amount = Number(buyAmount).toFixed(4) + " YAS"
655  actions.push({
656    account: "eosio",
657    name: "deposit",
658    authorization: [authorization],
659    data: {
660      owner: buyAccount,
661      amount: amount
662    }
663  })
664  actions.push({
665    account: "eosio",
666    name: "rentcpu",
667    authorization: [authorization],
668    data: { 
669      from: buyAccount, 
670      receiver: reciveAccount, 
671      loan_payment: amount,
672      loan_fund: "0.0000 YAS"
673    }
674  })
675
676  return api.transact({
677    actions: actions
678  }, {
679    blocksBehind: 3,
680    expireSeconds: 30
681  })
682}
683
684export const apiRentNet = (api, authorization, buyAccount, reciveAccount, buyAmount) => {
685  let actions = []
686  let amount = Number(buyAmount).toFixed(4) + " YAS"
687  actions.push({
688    account: "eosio",
689    name: "deposit",
690    authorization: [authorization],
691    data: {
692      owner: buyAccount,
693      amount: amount
694    }
695  })
696  actions.push({
697    account: "eosio",
698    name: "rentnet",
699    authorization: [authorization],
700    data: {
701      from: buyAccount,
702      receiver: reciveAccount,
703      loan_payment: amount,
704      loan_fund: "0.0000 YAS"
705    }
706  })
707
708  return api.transact({
709    actions: actions
710  }, {
711    blocksBehind: 3,
712    expireSeconds: 30
713  })
714}
715
716export const apiRefund = (api, authorization, account) => {
717  let actions = []
718  actions.push({
719    account: "eosio",
720    name: "refund",
721    authorization: [authorization],
722    data: {
723      owner: account
724    }
725  })
726
727  return api.transact({
728    actions: actions
729  }, {
730    blocksBehind: 3,
731    expireSeconds: 30
732  })
733}
734
735export const apiBidname = (api, authorization, bidder, newname, bid) => {
736  let actions = []
737  actions.push({
738    account: "eosio",
739    name: "bidname",
740    authorization: [authorization],
741    data: { 
742      bidder: bidder, 
743      newname: newname, 
744      bid: Number(bid).toFixed(4) + " YAS" 
745    }
746  })
747
748  return api.transact({
749    actions: actions
750  }, {
751    blocksBehind: 3,
752    expireSeconds: 30
753  })
754}
755
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Cucumber-gherkin on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)