From 564d02c17cb249cfd39dda1c1e32e941823f155f Mon Sep 17 00:00:00 2001 From: Wyatt Mufson Date: Sun, 27 Jan 2019 18:39:56 -0800 Subject: [PATCH] Added functioning tests for ontology build and invoke --- neoutils/ont.go | 13 +++++++++- neoutils/ont_test.go | 60 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/neoutils/ont.go b/neoutils/ont.go index c40289f..6858d41 100644 --- a/neoutils/ont.go +++ b/neoutils/ont.go @@ -44,7 +44,7 @@ func BuildOntologyInvocationTransaction(contractHex string, operation string, ar return raw, nil } -func OntologyInvoke(endpoint string, contractHex string, operation string, args []ontmobile.Parameter, gasPrice uint, gasLimit uint, wif string) (string, error) { +func OntologyInvoke(endpoint string, contractHex string, operation string, args []Parameter, gasPrice uint, gasLimit uint, wif string) (string, error) { raw, err := ontmobile.BuildInvocationTransaction(contractHex, operation, args, gasPrice, gasLimit, wif) if err != nil { return "", err @@ -57,3 +57,14 @@ func OntologyInvoke(endpoint string, contractHex string, operation string, args return txid, nil } + +type Parameter = ontmobile.Parameter +type ParameterType = ontmobile.ParameterType + +const ( + Address ParameterType = 0 + String ParameterType = 1 + Integer ParameterType = 2 + Fixed8 ParameterType = 3 + Array ParameterType = 4 +) diff --git a/neoutils/ont_test.go b/neoutils/ont_test.go index 3f4f898..47abdbd 100644 --- a/neoutils/ont_test.go +++ b/neoutils/ont_test.go @@ -34,6 +34,10 @@ func TestONTTransfer(t *testing.T) { func TestClaimONG(t *testing.T) { endpoint := "http://dappnode2.ont.io:20336" wif, _ := neoutils.NEP2Decrypt("", "") + if wif == "" { + log.Printf("No wif") + return + } gasPrice := int(500) gasLimit := int(20000) @@ -44,3 +48,59 @@ func TestClaimONG(t *testing.T) { } log.Printf("tx id =%v", txid) } + +func TestBuildOntologyInvocation(t *testing.T) { + wif := "" + if wif == "" { + log.Printf("No wif") + return + } + + account, _ := neoutils.GenerateFromWIF(wif) + address := account.Address + + addr := neoutils.Parameter{neoutils.Address, address} + val := neoutils.Parameter{neoutils.String, "Hi there"} + + args := []neoutils.Parameter{addr, val} + + gasPrice := uint(500) + gasLimit := uint(20000) + + txData, err := neoutils.BuildOntologyInvocationTransaction("c168e0fb1a2bddcd385ad013c2c98358eca5d4dc", "put", args, gasPrice, gasLimit, wif) + if err != nil { + log.Printf("Error creating invocation transaction: %s", err) + t.Fail() + } else { + log.Printf("Raw transaction: %s", txData) + } +} + +func TestOntologyInvoke(t *testing.T) { + wif := "" + if wif == "" { + log.Printf("No wif") + return + } + + account, _ := neoutils.GenerateFromWIF(wif) + address := account.Address + + addr := neoutils.Parameter{neoutils.Address, address} + val := neoutils.Parameter{neoutils.String, "Hi there"} + + args := []neoutils.Parameter{addr, val} + + gasPrice := uint(500) + gasLimit := uint(20000) + + endpoint := "http://polaris2.ont.io:20336" + + txid, err := neoutils.OntologyInvoke(endpoint, "c168e0fb1a2bddcd385ad013c2c98358eca5d4dc", "put", args, gasPrice, gasLimit, wif) + if err != nil { + log.Printf("Error creating invocation transaction: %s", err) + t.Fail() + } else { + log.Printf("tx id = %s", txid) + } +}