@@ -5,18 +5,18 @@ import (
5
5
"encoding/json"
6
6
"fmt"
7
7
"io"
8
+ "math/big"
8
9
"net/http"
9
10
"net/http/httptest"
10
11
"testing"
11
12
"time"
12
13
13
14
"github.com/NethermindEth/juno/core/felt"
14
15
starknetutils "github.com/NethermindEth/starknet.go/utils"
16
+ "github.com/smartcontractkit/chainlink-common/pkg/logger"
15
17
"github.com/stretchr/testify/assert"
16
18
"github.com/stretchr/testify/require"
17
19
18
- "github.com/smartcontractkit/chainlink-common/pkg/logger"
19
-
20
20
"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/starknet"
21
21
)
22
22
@@ -53,11 +53,10 @@ func TestERC20Client(t *testing.T) {
53
53
fmt .Printf ("%v %v\n " , reqdata .Selector , starknetutils .GetSelectorFromNameFelt ("latest_transmission_details" ).String ())
54
54
switch reqdata .Selector {
55
55
case starknetutils .GetSelectorFromNameFelt ("decimals" ).String ():
56
- // latest transmission details response
57
56
out = []byte (`{"result":["0x1"]}` )
58
57
case starknetutils .GetSelectorFromNameFelt ("balance_of" ).String ():
59
- // latest transmission details response
60
- out = []byte (`{"result":["0x0 "]}` )
58
+ // balance_of returns a u256 which is represented as two felts [lower 128 bits, higher 128 bits]
59
+ out = []byte (`{"result":["0x2", "0x9 "]}` )
61
60
default :
62
61
require .False (t , true , "unsupported contract method %s" , reqdata .Selector )
63
62
}
@@ -80,14 +79,17 @@ func TestERC20Client(t *testing.T) {
80
79
client , err := NewClient (reader , lggr , & felt .Zero )
81
80
assert .NoError (t , err )
82
81
83
- // contractAddress, err := starknetutils.HexToFelt(ocr2ContractAddress)
84
- // require.NoError(t, err)
85
-
86
82
t .Run ("get balance" , func (t * testing.T ) {
87
83
balance , err := client .BalanceOf (context .Background (), & felt .Zero )
88
84
require .NoError (t , err )
89
- require .Equal (t , uint64 (0 ), balance .Uint64 ())
90
- // require.Equal(t, new(big.Int), balance)
85
+
86
+ // calculate the expected u256 value of two felts [0x2, 0x9]
87
+ low := new (big.Int ).SetUint64 (2 )
88
+ high := new (big.Int ).SetUint64 (9 )
89
+ summand := new (big.Int ).Lsh (high , 128 )
90
+ expectedTotal := new (big.Int ).Add (low , summand )
91
+
92
+ require .Equal (t , expectedTotal .String (), balance .String ())
91
93
})
92
94
93
95
t .Run ("get decimals" , func (t * testing.T ) {
0 commit comments