github.com/ethersphere/bee/v2@v2.2.0/pkg/settlement/swap/priceoracle/priceoracle_test.go (about) 1 // Copyright 2021 The Swarm Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package priceoracle_test 6 7 import ( 8 "context" 9 "math/big" 10 "testing" 11 12 "github.com/ethereum/go-ethereum/common" 13 "github.com/ethersphere/bee/v2/pkg/log" 14 "github.com/ethersphere/bee/v2/pkg/settlement/swap/priceoracle" 15 transactionmock "github.com/ethersphere/bee/v2/pkg/transaction/mock" 16 "github.com/ethersphere/bee/v2/pkg/util/abiutil" 17 "github.com/ethersphere/go-price-oracle-abi/priceoracleabi" 18 ) 19 20 var ( 21 priceOracleABI = abiutil.MustParseABI(priceoracleabi.PriceOracleABIv0_2_0) 22 ) 23 24 func TestExchangeGetPrice(t *testing.T) { 25 t.Parallel() 26 27 priceOracleAddress := common.HexToAddress("0xabcd") 28 29 expectedPrice := big.NewInt(100) 30 expectedDeduce := big.NewInt(200) 31 32 result := make([]byte, 64) 33 expectedPrice.FillBytes(result[0:32]) 34 expectedDeduce.FillBytes(result[32:64]) 35 36 ex := priceoracle.New( 37 log.Noop, 38 priceOracleAddress, 39 transactionmock.New( 40 transactionmock.WithABICall( 41 &priceOracleABI, 42 priceOracleAddress, 43 result, 44 "getPrice", 45 ), 46 ), 47 1, 48 ) 49 50 price, deduce, err := ex.GetPrice(context.Background()) 51 if err != nil { 52 t.Fatal(err) 53 } 54 55 if expectedPrice.Cmp(price) != 0 { 56 t.Fatalf("got wrong price. wanted %d, got %d", expectedPrice, price) 57 } 58 59 if expectedDeduce.Cmp(deduce) != 0 { 60 t.Fatalf("got wrong deduce. wanted %d, got %d", expectedDeduce, deduce) 61 } 62 }