Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Commit

Permalink
Added functioning tests for ontology build and invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyatt Mufson committed Jan 28, 2019
1 parent 3462f7b commit 564d02c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
13 changes: 12 additions & 1 deletion neoutils/ont.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
60 changes: 60 additions & 0 deletions neoutils/ont_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}

0 comments on commit 564d02c

Please sign in to comment.