11import axios from "axios" ; // md-ignore
2- import { promises } from "fs" ; // md-ignore
2+ import * as fs from "fs" ; // md-ignore
33import path from "path" ; // md-ignore
44import {
55 Abi ,
@@ -20,7 +20,6 @@ import {
2020 U32Value ,
2121 U64Value ,
2222} from "../src" ; // md-ignore
23- import { loadAbiRegistry } from "../src/testutils" ;
2423// md-start
2524( async ( ) => {
2625 // ### Smart Contracts
@@ -33,9 +32,8 @@ import { loadAbiRegistry } from "../src/testutils";
3332 // #### Loading the ABI from a file
3433 // ```js
3534 {
36- let abiJson = await promises . readFile ( "../src/testData/adder.abi.json" , { encoding : "utf8" } ) ;
37- let abiObj = JSON . parse ( abiJson ) ;
38- let abi = Abi . create ( abiObj ) ;
35+ let abiJson = await fs . promises . readFile ( "../src/testdata/adder.abi.json" , { encoding : "utf8" } ) ;
36+ const abi = Abi . create ( JSON . parse ( abiJson ) ) ;
3937 }
4038 // ```
4139
@@ -104,9 +102,12 @@ import { loadAbiRegistry } from "../src/testutils";
104102 sender . nonce = await entrypoint . recallAccountNonce ( sender . address ) ;
105103
106104 // load the contract bytecode
107- const bytecode = await promises . readFile ( "../src/testData /adder.wasm" ) ;
105+ const bytecode = await fs . promises . readFile ( "../src/testdata /adder.wasm" ) ;
108106 // load the abi file
109- const abi = await loadAbiRegistry ( "../src/testdata/adder.abi.json" ) ;
107+ const jsonContent : string = await fs . promises . readFile ( "../src/testdata/adder.abi.json" , {
108+ encoding : "utf8" ,
109+ } ) ;
110+ const abi = Abi . create ( JSON . parse ( jsonContent ) ) ;
110111
111112 const controller = entrypoint . createSmartContractController ( abi ) ;
112113
@@ -142,8 +143,10 @@ import { loadAbiRegistry } from "../src/testutils";
142143 // ```js
143144 {
144145 // We use the transaction hash we got when broadcasting the transaction
145-
146- const abi = await loadAbiRegistry ( "../src/testdata/adder.abi.json" ) ;
146+ const jsonContent : string = await fs . promises . readFile ( "../src/testdata/adder.abi.json" , {
147+ encoding : "utf8" ,
148+ } ) ;
149+ const abi = Abi . create ( JSON . parse ( jsonContent ) ) ;
147150 const entrypoint = new DevnetEntrypoint ( ) ;
148151 const controller = entrypoint . createSmartContractController ( abi ) ;
149152 const outcome = await controller . awaitCompletedDeploy ( "txHash" ) ; // waits for transaction completion and parses the result
@@ -176,7 +179,7 @@ import { loadAbiRegistry } from "../src/testutils";
176179 {
177180 const entrypoint = new DevnetEntrypoint ( ) ;
178181 const factory = entrypoint . createSmartContractTransactionsFactory ( ) ;
179- const bytecode = await promises . readFile ( "../contracts/adder.wasm" ) ;
182+ const bytecode = await fs . promises . readFile ( "../contracts/adder.wasm" ) ;
180183
181184 // For deploy arguments, use "TypedValue" objects if you haven't provided an ABI to the factory: // md-as-comment
182185 let args : any [ ] = [ new BigUIntValue ( 42 ) ] ;
@@ -185,7 +188,7 @@ import { loadAbiRegistry } from "../src/testutils";
185188
186189 const filePath = path . join ( "../src" , "testdata" , "testwallets" , "alice.pem" ) ;
187190 const alice = await Account . newFromPem ( filePath ) ;
188- const deployTransaction = factory . createTransactionForDeploy ( alice . address , {
191+ const deployTransaction = await factory . createTransactionForDeploy ( alice . address , {
189192 bytecode : bytecode ,
190193 gasLimit : 6000000n ,
191194 arguments : args ,
@@ -209,7 +212,7 @@ import { loadAbiRegistry } from "../src/testutils";
209212 const factory = entrypoint . createSmartContractTransactionsFactory ( ) ;
210213
211214 // load the contract bytecode
212- const bytecode = await promises . readFile ( "../src/testData /adder.wasm" ) ;
215+ const bytecode = await fs . promises . readFile ( "../src/testdata /adder.wasm" ) ;
213216
214217 // For deploy arguments, use "TypedValue" objects if you haven't provided an ABI to the factory: // md-as-comment
215218 let args : any [ ] = [ new BigUIntValue ( 42 ) ] ;
@@ -265,7 +268,10 @@ import { loadAbiRegistry } from "../src/testutils";
265268 sender . nonce = await entrypoint . recallAccountNonce ( sender . address ) ;
266269
267270 // load the abi file
268- const abi = await loadAbiRegistry ( "../src/testdata/adder.abi.json" ) ;
271+ const jsonContent : string = await fs . promises . readFile ( "../src/testdata/adder.abi.json" , {
272+ encoding : "utf8" ,
273+ } ) ;
274+ const abi = Abi . create ( JSON . parse ( jsonContent ) ) ;
269275 const controller = entrypoint . createSmartContractController ( abi ) ;
270276
271277 const contractAddress = Address . newFromBech32 ( "erd1qqqqqqqqqqqqqpgq7cmfueefdqkjsnnjnwydw902v8pwjqy3d8ssd4meug" ) ;
@@ -317,7 +323,10 @@ import { loadAbiRegistry } from "../src/testutils";
317323 sender . nonce = await entrypoint . recallAccountNonce ( sender . address ) ;
318324
319325 // load the abi file
320- const abi = await loadAbiRegistry ( "../src/testdata/adder.abi.json" ) ;
326+ const jsonContent : string = await fs . promises . readFile ( "../src/testdata/adder.abi.json" , {
327+ encoding : "utf8" ,
328+ } ) ;
329+ const abi = Abi . create ( JSON . parse ( jsonContent ) ) ;
321330
322331 // get the smart contracts controller
323332 const controller = entrypoint . createSmartContractController ( abi ) ;
@@ -407,7 +416,10 @@ import { loadAbiRegistry } from "../src/testutils";
407416 {
408417 // load the abi file
409418 const entrypoint = new DevnetEntrypoint ( ) ;
410- const abi = await loadAbiRegistry ( "../src/testdata/adder.abi.json" ) ;
419+ const jsonContent : string = await fs . promises . readFile ( "../src/testdata/adder.abi.json" , {
420+ encoding : "utf8" ,
421+ } ) ;
422+ const abi = Abi . create ( JSON . parse ( jsonContent ) ) ;
411423 const parser = new SmartContractTransactionsOutcomeParser ( { abi } ) ;
412424 const txHash = "b3ae88ad05c464a74db73f4013de05abcfcb4fb6647c67a262a6cfdf330ef4a9" ;
413425 const transactionOnNetwork = await entrypoint . getTransaction ( txHash ) ;
@@ -426,7 +438,10 @@ import { loadAbiRegistry } from "../src/testutils";
426438 {
427439 // load the abi files
428440 const entrypoint = new DevnetEntrypoint ( ) ;
429- const abi = await loadAbiRegistry ( "../src/testdata/adder.abi.json" ) ;
441+ const jsonContent : string = await fs . promises . readFile ( "../src/testdata/adder.abi.json" , {
442+ encoding : "utf8" ,
443+ } ) ;
444+ const abi = Abi . create ( JSON . parse ( jsonContent ) ) ;
430445 const parser = new TransactionEventsParser ( { abi } ) ;
431446 const txHash = "b3ae88ad05c464a74db73f4013de05abcfcb4fb6647c67a262a6cfdf330ef4a9" ;
432447 const transactionOnNetwork = await entrypoint . getTransaction ( txHash ) ;
@@ -441,7 +456,10 @@ import { loadAbiRegistry } from "../src/testutils";
441456 // Let's encode a struct called EsdtTokenPayment (of [multisig](https://github.com/multiversx/mx-contracts-rs/tree/main/contracts/multisig) contract) into binary data.
442457 // ```js
443458 {
444- const abi = await loadAbiRegistry ( "../src/testdata/multisig-full.abi.json" ) ;
459+ const jsonContent : string = await fs . promises . readFile ( "../src/testdata/multisig-full.abi.json" , {
460+ encoding : "utf8" ,
461+ } ) ;
462+ const abi = Abi . create ( JSON . parse ( jsonContent ) ) ;
445463 const paymentType = abi . getStruct ( "EsdtTokenPayment" ) ;
446464 const codec = new BinaryCodec ( ) ;
447465
@@ -460,7 +478,10 @@ import { loadAbiRegistry } from "../src/testutils";
460478 // Now let's decode a struct using the ABI.
461479 // ```js
462480 {
463- const abi = await loadAbiRegistry ( "../src/testdata/multisig-full.abi.json" ) ;
481+ const jsonContent : string = await fs . promises . readFile ( "../src/testdata/multisig-full.abi.json" , {
482+ encoding : "utf8" ,
483+ } ) ;
484+ const abi = Abi . create ( JSON . parse ( jsonContent ) ) ;
464485 const actionStructType = abi . getEnum ( "Action" ) ;
465486 const data = Buffer . from (
466487 "0500000000000000000500d006f73c4221216fa679bc559005584c4f1160e569e1000000012a0000000003616464000000010000000107" ,
@@ -483,7 +504,10 @@ import { loadAbiRegistry } from "../src/testutils";
483504 {
484505 const entrypoint = new DevnetEntrypoint ( ) ;
485506 const contractAddress = Address . newFromBech32 ( "erd1qqqqqqqqqqqqqpgq7cmfueefdqkjsnnjnwydw902v8pwjqy3d8ssd4meug" ) ;
486- const abi = await loadAbiRegistry ( "../src/testdata/adder.abi.json" ) ;
507+ const jsonContent : string = await fs . promises . readFile ( "../src/testdata/adder.abi.json" , {
508+ encoding : "utf8" ,
509+ } ) ;
510+ const abi = Abi . create ( JSON . parse ( jsonContent ) ) ;
487511
488512 // create the controller
489513 const controller = entrypoint . createSmartContractController ( abi ) ;
@@ -501,7 +525,10 @@ import { loadAbiRegistry } from "../src/testutils";
501525 const entrypoint = new DevnetEntrypoint ( ) ;
502526
503527 // load the abi
504- const abi = await loadAbiRegistry ( "../src/testdata/adder.abi.json" ) ;
528+ const jsonContent : string = await fs . promises . readFile ( "../src/testdata/adder.abi.json" , {
529+ encoding : "utf8" ,
530+ } ) ;
531+ const abi = Abi . create ( JSON . parse ( jsonContent ) ) ;
505532
506533 // the contract address we'll query
507534 const contractAddress = Address . newFromBech32 ( "erd1qqqqqqqqqqqqqpgq7cmfueefdqkjsnnjnwydw902v8pwjqy3d8ssd4meug" ) ;
@@ -534,13 +561,16 @@ import { loadAbiRegistry } from "../src/testutils";
534561 sender . nonce = await entrypoint . recallAccountNonce ( sender . address ) ;
535562
536563 // load the abi
537- const abi = await loadAbiRegistry ( "../src/testdata/adder.abi.json" ) ;
564+ const jsonContent : string = await fs . promises . readFile ( "../src/testdata/adder.abi.json" , {
565+ encoding : "utf8" ,
566+ } ) ;
567+ const abi = Abi . create ( JSON . parse ( jsonContent ) ) ;
538568
539569 // create the controller
540570 const controller = entrypoint . createSmartContractController ( abi ) ;
541571
542572 // load the contract bytecode; this is the new contract code, the one we want to upgrade to
543- const bytecode = await promises . readFile ( "../src/testData /adder.wasm" ) ;
573+ const bytecode = await fs . promises . readFile ( "../src/testdata /adder.wasm" ) ;
544574
545575 // For deploy arguments, use "TypedValue" objects if you haven't provided an ABI to the factory: // md-as-comment
546576 let args : any [ ] = [ new U32Value ( 42 ) ] ;
0 commit comments