core: allow to compile test contracts with yaml config
And refactored Rubl test contract (it should support NEP-17 and onNEP17Payment).
This commit is contained in:
parent
ee76db9ff2
commit
0a5072a1da
9 changed files with 59 additions and 24 deletions
|
@ -60,8 +60,8 @@ type rpcTestCase struct {
|
|||
check func(t *testing.T, e *executor, result interface{})
|
||||
}
|
||||
|
||||
const testContractHash = "1e1c3024bd955ff3baf7cb92e3b7608c7bb3712b"
|
||||
const deploymentTxHash = "9218bba2a6e145aab5dc21c4bb16a650efdf0b9b16b0d69bd754278363a1d1c2"
|
||||
const testContractHash = "c6ca2347bb84b99807221365c900ec069a265e7c"
|
||||
const deploymentTxHash = "fdd4f9252cde778010d14e9710efeeb80796fd38d778e9943c1d5bb2dc656c99"
|
||||
const genesisBlockHash = "5b60644c6c6f58faca72c70689d7ed1f40c2e795772bd0de5a88e983ad55080c"
|
||||
|
||||
const verifyContractHash = "5bb4bac40e961e334ba7bd36d2496010f67e246e"
|
||||
|
@ -1650,7 +1650,7 @@ func checkNep17Balances(t *testing.T, e *executor, acc interface{}) {
|
|||
},
|
||||
{
|
||||
Asset: e.chain.UtilityTokenHash(),
|
||||
Amount: "68992647820",
|
||||
Amount: "68992456820",
|
||||
LastUpdated: 10,
|
||||
}},
|
||||
Address: testchain.PrivateKeyByID(0).GetScriptHash().StringLE(),
|
||||
|
|
19
pkg/rpc/server/testdata/test_contract.go
vendored
19
pkg/rpc/server/testdata/test_contract.go
vendored
|
@ -1,6 +1,9 @@
|
|||
package testdata
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/management"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||
)
|
||||
|
@ -19,7 +22,7 @@ func Init() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func Transfer(from, to []byte, amount int, data interface{}) bool {
|
||||
func Transfer(from, to interop.Hash160, amount int, data interface{}) bool {
|
||||
ctx := storage.GetContext()
|
||||
if len(from) != 20 {
|
||||
runtime.Log("invalid 'from' address")
|
||||
|
@ -55,22 +58,22 @@ func Transfer(from, to []byte, amount int, data interface{}) bool {
|
|||
storage.Put(ctx, to, toBalance)
|
||||
|
||||
runtime.Notify("Transfer", from, to, amount)
|
||||
|
||||
if management.GetContract(to) != nil {
|
||||
contract.Call(to, "onNEP17Payment", contract.All, from, amount, data)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func BalanceOf(addr []byte) int {
|
||||
func BalanceOf(account interop.Hash160) int {
|
||||
ctx := storage.GetContext()
|
||||
if len(addr) != 20 {
|
||||
runtime.Log("invalid address")
|
||||
return 0
|
||||
if len(account) != 20 {
|
||||
panic("invalid address")
|
||||
}
|
||||
var amount int
|
||||
val := storage.Get(ctx, addr)
|
||||
val := storage.Get(ctx, account)
|
||||
if val != nil {
|
||||
amount = val.(int)
|
||||
}
|
||||
runtime.Notify("balanceOf", addr, amount)
|
||||
return amount
|
||||
}
|
||||
|
||||
|
|
12
pkg/rpc/server/testdata/test_contract.yml
vendored
Normal file
12
pkg/rpc/server/testdata/test_contract.yml
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
name: "Rubl"
|
||||
supportedstandards: ["NEP-17"]
|
||||
safemethods: ["balanceOf", "decimals", "symbol", "totalSupply"]
|
||||
events:
|
||||
- name: Transfer
|
||||
parameters:
|
||||
- name: from
|
||||
type: Hash160
|
||||
- name: to
|
||||
type: Hash160
|
||||
- name: amount
|
||||
type: Integer
|
BIN
pkg/rpc/server/testdata/testblocks.acc
vendored
BIN
pkg/rpc/server/testdata/testblocks.acc
vendored
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue