11import BigNumber from "bignumber.js" ;
22import { assert } from "chai" ;
3+ import { Account } from "../accounts" ;
34import { Address } from "../core/address" ;
45import { SmartContractQueryResponse } from "../core/smartContractQuery" ;
56import { Token , TokenTransfer } from "../core/tokens" ;
67import { Transaction } from "../core/transaction" ;
7- import { TransactionComputer } from "../core/transactionComputer" ;
88import { SmartContractController } from "../smartContracts" ;
9- import {
10- loadAbiRegistry ,
11- loadTestWallets ,
12- MockNetworkProvider ,
13- setupUnitTestWatcherTimeouts ,
14- TestWallet ,
15- } from "../testutils" ;
9+ import { loadAbiRegistry , MockNetworkProvider , setupUnitTestWatcherTimeouts } from "../testutils" ;
10+ import { getTestWalletsPath } from "../testutils/utils" ;
1611import { ContractFunction } from "./function" ;
1712import { Interaction } from "./interaction" ;
1813import { SmartContract } from "./smartContract" ;
@@ -21,11 +16,10 @@ import { BigUIntValue, BytesValue, OptionalValue, OptionValue, TokenIdentifierVa
2116describe ( "test smart contract interactor" , function ( ) {
2217 let dummyAddress = new Address ( "erd1qqqqqqqqqqqqqpgqak8zt22wl2ph4tswtyc39namqx6ysa2sd8ss4xmlj3" ) ;
2318 let provider = new MockNetworkProvider ( ) ;
24- let alice : TestWallet ;
25- const transactionComputer = new TransactionComputer ( ) ;
19+ let alice : Account ;
2620
2721 before ( async function ( ) {
28- ( { alice } = await loadTestWallets ( ) ) ;
22+ alice = await Account . newFromPem ( ` ${ getTestWalletsPath ( ) } /alice.pem` ) ;
2923 } ) ;
3024
3125 it ( "should set transaction fields" , async function ( ) {
@@ -249,23 +243,23 @@ describe("test smart contract interactor", function () {
249243 // Execute, do not wait for execution
250244 let transaction = interaction . withSender ( alice . address ) . withNonce ( 0n ) . buildTransaction ( ) ;
251245 transaction . sender = alice . address ;
252- transaction . signature = await alice . signer . sign ( transactionComputer . computeBytesForSigning ( transaction ) ) ;
246+ transaction . signature = await alice . signTransaction ( transaction ) ;
253247 let hash = await provider . sendTransaction ( transaction ) ;
254248 assert . equal ( transaction . nonce , 0n ) ;
255249 assert . equal ( transaction . data . toString ( ) , "getUltimateAnswer" ) ;
256250 assert . equal ( hash , "3579ad09099feb9755c860ddd225251170806d833342e912fccdfe2ed5c3a364" ) ;
257251
258252 transaction = interaction . withNonce ( 1n ) . buildTransaction ( ) ;
259253 transaction . sender = alice . address ;
260- transaction . signature = await alice . signer . sign ( transactionComputer . computeBytesForSigning ( transaction ) ) ;
254+ transaction . signature = await alice . signTransaction ( transaction ) ;
261255 hash = await provider . sendTransaction ( transaction ) ;
262256 assert . equal ( transaction . nonce , 1n ) ;
263257 assert . equal ( hash , "ad513ce7c5d371d30e48f073326899766736eac1ac231d847d45bc3facbcb496" ) ;
264258
265259 // Execute, and wait for execution
266260 transaction = interaction . withNonce ( 2n ) . buildTransaction ( ) ;
267261 transaction . sender = alice . address ;
268- transaction . signature = await alice . signer . sign ( transactionComputer . computeBytesForSigning ( transaction ) ) ;
262+ transaction . signature = await alice . signTransaction ( transaction ) ;
269263 provider . mockGetTransactionWithAnyHashAsNotarizedWithOneResult ( "@6f6b@2bs" , "getUltimateAnswer" ) ;
270264 hash = await provider . sendTransaction ( transaction ) ;
271265 let responseExecute = await controller . awaitCompletedExecute ( hash ) ;
@@ -314,9 +308,7 @@ describe("test smart contract interactor", function () {
314308 . withChainID ( "mock" )
315309 . buildTransaction ( ) ;
316310
317- incrementTransaction . signature = await alice . signer . sign (
318- transactionComputer . computeBytesForSigning ( incrementTransaction ) ,
319- ) ;
311+ incrementTransaction . signature = await alice . signTransaction ( incrementTransaction ) ;
320312 provider . mockGetTransactionWithAnyHashAsNotarizedWithOneResult ( "@6f6b@08" , "increment" ) ;
321313 let hash = await provider . sendTransaction ( incrementTransaction ) ;
322314 let responseExecute = await controller . awaitCompletedExecute ( hash ) ;
@@ -330,22 +322,16 @@ describe("test smart contract interactor", function () {
330322 . withChainID ( "mock" )
331323 . buildTransaction ( ) ;
332324
333- decrementTransaction . signature = await alice . signer . sign (
334- transactionComputer . computeBytesForSigning ( decrementTransaction ) ,
335- ) ;
325+ decrementTransaction . signature = await alice . signTransaction ( decrementTransaction ) ;
336326 await provider . sendTransaction ( decrementTransaction ) ;
337327 // Decrement #2
338328 decrementTransaction = decrementInteraction . withNonce ( 16n ) . buildTransaction ( ) ;
339- decrementTransaction . signature = await alice . signer . sign (
340- transactionComputer . computeBytesForSigning ( decrementTransaction ) ,
341- ) ;
329+ decrementTransaction . signature = await alice . signTransaction ( decrementTransaction ) ;
342330 await provider . sendTransaction ( decrementTransaction ) ;
343331 // Decrement #3
344332
345333 decrementTransaction = decrementInteraction . withNonce ( 17n ) . buildTransaction ( ) ;
346- decrementTransaction . signature = await alice . signer . sign (
347- transactionComputer . computeBytesForSigning ( decrementTransaction ) ,
348- ) ;
334+ decrementTransaction . signature = await alice . signTransaction ( decrementTransaction ) ;
349335 provider . mockGetTransactionWithAnyHashAsNotarizedWithOneResult ( "@6f6b@05" , "decrement" ) ;
350336 hash = await provider . sendTransaction ( decrementTransaction ) ;
351337 responseExecute = await controller . awaitCompletedExecute ( hash ) ;
@@ -386,9 +372,7 @@ describe("test smart contract interactor", function () {
386372 . withChainID ( "mock" )
387373 . buildTransaction ( ) ;
388374
389- startTransaction . signature = await alice . signer . sign (
390- transactionComputer . computeBytesForSigning ( startTransaction ) ,
391- ) ;
375+ startTransaction . signature = await alice . signTransaction ( startTransaction ) ;
392376
393377 provider . mockGetTransactionWithAnyHashAsNotarizedWithOneResult ( "@6f6b" , "start" ) ;
394378 let hash = await provider . sendTransaction ( startTransaction ) ;
@@ -405,9 +389,7 @@ describe("test smart contract interactor", function () {
405389 . withChainID ( "mock" )
406390 . buildTransaction ( ) ;
407391
408- statusTransaction . signature = await alice . signer . sign (
409- transactionComputer . computeBytesForSigning ( statusTransaction ) ,
410- ) ;
392+ statusTransaction . signature = await alice . signTransaction ( statusTransaction ) ;
411393 provider . mockGetTransactionWithAnyHashAsNotarizedWithOneResult ( "@6f6b@01" , "status" ) ;
412394
413395 hash = await provider . sendTransaction ( startTransaction ) ;
@@ -425,9 +407,7 @@ describe("test smart contract interactor", function () {
425407 . withChainID ( "mock" )
426408 . buildTransaction ( ) ;
427409
428- getLotteryInfoTransaction . signature = await alice . signer . sign (
429- transactionComputer . computeBytesForSigning ( getLotteryInfoTransaction ) ,
430- ) ;
410+ getLotteryInfoTransaction . signature = await alice . signTransaction ( getLotteryInfoTransaction ) ;
431411 provider . mockGetTransactionWithAnyHashAsNotarizedWithOneResult (
432412 "@6f6b@0000000b6c75636b792d746f6b656e000000010100000000000000005fc2b9dbffffffff00000001640000000a140ec80fa7ee88000000" ,
433413 "getLotteryInfo" ,
0 commit comments