github.com/0chain/gosdk@v1.17.11/core/tokenrate/bancor_test.go (about)

     1  package tokenrate
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestBancorJson(t *testing.T) {
    11  	js := ` {
    12  		"data": {
    13  				"dltId": "0xb9EF770B6A5e12E45983C5D80545258aA38F3B78",
    14  				"symbol": "ZCN",
    15  				"decimals": 10,
    16  				"rate": {
    17  						"bnt": "0.271257342312491431",
    18  						"usd": "0.118837",
    19  						"eur": "0.121062",
    20  						"eth": "0.000089243665620809"
    21  				},
    22  				"rate24hAgo": {
    23  						"bnt": "0.273260935543748855",
    24  						"usd": "0.120972",
    25  						"eur": "0.126301",
    26  						"eth": "0.000094001761827049"
    27  				}
    28  		},
    29  		"timestamp": {
    30  				"ethereum": {
    31  						"block": 15644407,
    32  						"timestamp": 1664519843
    33  				}
    34  		}
    35  	}`
    36  	bs := &bancorResponse{}
    37  
    38  	err := json.Unmarshal([]byte(js), bs)
    39  	require.Nil(t, err)
    40  
    41  	require.Equal(t, 0.118837, bs.Data.Rate["usd"].Value)
    42  	require.Equal(t, 0.120972, bs.Data.Rate24hAgo["usd"].Value)
    43  
    44  }