client: add NNS price getter

This commit is contained in:
Roman Khimov 2021-03-16 22:59:04 +03:00
parent f308a9995d
commit 87d4939093
2 changed files with 21 additions and 0 deletions

View file

@ -16,3 +16,12 @@ func (c *Client) GetOraclePrice() (int64, error) {
}
return c.invokeNativeGetMethod(oracleHash, "getPrice")
}
// GetNNSPrice invokes `getPrice` method on a native NameService contract.
func (c *Client) GetNNSPrice() (int64, error) {
nnsHash, err := c.GetNativeContractHash(nativenames.NameService)
if err != nil {
return 0, fmt.Errorf("failed to get native NameService hash: %w", err)
}
return c.invokeNativeGetMethod(nnsHash, "getPrice")
}

View file

@ -452,6 +452,18 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
},
},
},
"getNNSPrice": {
{
name: "positive",
invoke: func(c *Client) (interface{}, error) {
return c.GetNNSPrice()
},
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"state":"HALT","gasconsumed":"2007390","script":"EMAMDWdldEZlZVBlckJ5dGUMFJphpG7sl7iTBtfOgfFbRiCR0AkyQWJ9W1I=","stack":[{"type":"Integer","value":"1000000"}],"tx":null}}`,
result: func(c *Client) interface{} {
return int64(1000000)
},
},
},
"getMaxNotValidBeforeDelta": {
{
name: "positive",