mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-01-07 09:50:36 +00:00
Merge pull request #1250 from nspcc-dev/fix/nep5
Fix `getnep5*` RPC format
This commit is contained in:
commit
e135719c38
6 changed files with 41 additions and 93 deletions
|
@ -799,6 +799,7 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to persist invocation results")
|
return errors.Wrap(err, "failed to persist invocation results")
|
||||||
}
|
}
|
||||||
|
var index uint32
|
||||||
for _, note := range systemInterop.notifications {
|
for _, note := range systemInterop.notifications {
|
||||||
arr, ok := note.Item.Value().([]vm.StackItem)
|
arr, ok := note.Item.Value().([]vm.StackItem)
|
||||||
if !ok || len(arr) != 4 {
|
if !ok || len(arr) != 4 {
|
||||||
|
@ -824,7 +825,8 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
|
||||||
}
|
}
|
||||||
amount = emit.BytesToInt(bs)
|
amount = emit.BytesToInt(bs)
|
||||||
}
|
}
|
||||||
bc.processNEP5Transfer(cache, tx, block, note.ScriptHash, from, to, amount.Int64())
|
bc.processNEP5Transfer(cache, tx, block, note.ScriptHash, from, to, amount.Int64(), index)
|
||||||
|
index++
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bc.log.Warn("contract invocation failed",
|
bc.log.Warn("contract invocation failed",
|
||||||
|
@ -911,7 +913,7 @@ func parseUint160(addr []byte) util.Uint160 {
|
||||||
return util.Uint160{}
|
return util.Uint160{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *Blockchain) processNEP5Transfer(cache *dao.Cached, tx *transaction.Transaction, b *block.Block, sc util.Uint160, from, to []byte, amount int64) {
|
func (bc *Blockchain) processNEP5Transfer(cache *dao.Cached, tx *transaction.Transaction, b *block.Block, sc util.Uint160, from, to []byte, amount int64, index uint32) {
|
||||||
toAddr := parseUint160(to)
|
toAddr := parseUint160(to)
|
||||||
fromAddr := parseUint160(from)
|
fromAddr := parseUint160(from)
|
||||||
transfer := &state.NEP5Transfer{
|
transfer := &state.NEP5Transfer{
|
||||||
|
@ -921,6 +923,7 @@ func (bc *Blockchain) processNEP5Transfer(cache *dao.Cached, tx *transaction.Tra
|
||||||
Block: b.Index,
|
Block: b.Index,
|
||||||
Timestamp: b.Timestamp,
|
Timestamp: b.Timestamp,
|
||||||
Tx: tx.Hash(),
|
Tx: tx.Hash(),
|
||||||
|
Index: index,
|
||||||
}
|
}
|
||||||
if !fromAddr.Equals(util.Uint160{}) {
|
if !fromAddr.Equals(util.Uint160{}) {
|
||||||
balances, err := cache.GetNEP5Balances(fromAddr)
|
balances, err := cache.GetNEP5Balances(fromAddr)
|
||||||
|
|
|
@ -409,7 +409,7 @@ func TestCreateBasicChain(t *testing.T) {
|
||||||
sh = hash.Hash160(avm)
|
sh = hash.Hash160(avm)
|
||||||
t.Logf("contractHash (new): %s", sh.StringLE())
|
t.Logf("contractHash (new): %s", sh.StringLE())
|
||||||
|
|
||||||
transferTx = newNEP5Transfer(sh, priv1.GetScriptHash(), priv0.GetScriptHash(), 3)
|
transferTx = newNEP5Transfer(sh, priv1.GetScriptHash(), priv0.GetScriptHash(), 2, 1)
|
||||||
b = bc.newBlock(newMinerTX(), transferTx)
|
b = bc.newBlock(newMinerTX(), transferTx)
|
||||||
require.NoError(t, bc.AddBlock(b))
|
require.NoError(t, bc.AddBlock(b))
|
||||||
|
|
||||||
|
@ -446,10 +446,12 @@ func TestCreateBasicChain(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newNEP5Transfer(sc, from, to util.Uint160, amount int64) *transaction.Transaction {
|
func newNEP5Transfer(sc, from, to util.Uint160, amounts ...int64) *transaction.Transaction {
|
||||||
w := io.NewBufBinWriter()
|
w := io.NewBufBinWriter()
|
||||||
emit.AppCallWithOperationAndArgs(w.BinWriter, sc, "transfer", from, to, amount)
|
for i := range amounts {
|
||||||
emit.Opcode(w.BinWriter, opcode.THROWIFNOT)
|
emit.AppCallWithOperationAndArgs(w.BinWriter, sc, "transfer", from, to, amounts[i])
|
||||||
|
emit.Opcode(w.BinWriter, opcode.THROWIFNOT)
|
||||||
|
}
|
||||||
|
|
||||||
script := w.Bytes()
|
script := w.Bytes()
|
||||||
return transaction.NewInvocationTX(script, 0)
|
return transaction.NewInvocationTX(script, 0)
|
||||||
|
|
|
@ -20,7 +20,7 @@ type NEP5TransferLog struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NEP5TransferSize is a size of a marshaled NEP5Transfer struct in bytes.
|
// NEP5TransferSize is a size of a marshaled NEP5Transfer struct in bytes.
|
||||||
const NEP5TransferSize = util.Uint160Size*3 + 8 + 4 + 4 + util.Uint256Size
|
const NEP5TransferSize = util.Uint160Size*3 + 8 + 4 + 4 + util.Uint256Size + 4
|
||||||
|
|
||||||
// NEP5Transfer represents a single NEP5 Transfer event.
|
// NEP5Transfer represents a single NEP5 Transfer event.
|
||||||
type NEP5Transfer struct {
|
type NEP5Transfer struct {
|
||||||
|
@ -39,6 +39,8 @@ type NEP5Transfer struct {
|
||||||
Timestamp uint32
|
Timestamp uint32
|
||||||
// Tx is a hash the transaction.
|
// Tx is a hash the transaction.
|
||||||
Tx util.Uint256
|
Tx util.Uint256
|
||||||
|
// Index is the index of this transfer in the corresponding tx.
|
||||||
|
Index uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// NEP5Balances is a map of the NEP5 contract hashes
|
// NEP5Balances is a map of the NEP5 contract hashes
|
||||||
|
@ -152,6 +154,7 @@ func (t *NEP5Transfer) EncodeBinary(w *io.BinWriter) {
|
||||||
w.WriteU32LE(t.Block)
|
w.WriteU32LE(t.Block)
|
||||||
w.WriteU32LE(t.Timestamp)
|
w.WriteU32LE(t.Timestamp)
|
||||||
w.WriteU64LE(uint64(t.Amount))
|
w.WriteU64LE(uint64(t.Amount))
|
||||||
|
w.WriteU32LE(t.Index)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecodeBinary implements io.Serializable interface.
|
// DecodeBinary implements io.Serializable interface.
|
||||||
|
@ -163,4 +166,5 @@ func (t *NEP5Transfer) DecodeBinary(r *io.BinReader) {
|
||||||
t.Block = r.ReadU32LE()
|
t.Block = r.ReadU32LE()
|
||||||
t.Timestamp = r.ReadU32LE()
|
t.Timestamp = r.ReadU32LE()
|
||||||
t.Amount = int64(r.ReadU64LE())
|
t.Amount = int64(r.ReadU64LE())
|
||||||
|
t.Index = r.ReadU32LE()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -27,9 +26,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
|
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -577,13 +574,8 @@ func (s *Server) getNEP5Balances(ps request.Params) (interface{}, *response.Erro
|
||||||
Balances: []result.NEP5Balance{},
|
Balances: []result.NEP5Balance{},
|
||||||
}
|
}
|
||||||
if as != nil {
|
if as != nil {
|
||||||
cache := make(map[util.Uint160]int64)
|
|
||||||
for h, bal := range as.Trackers {
|
for h, bal := range as.Trackers {
|
||||||
dec, err := s.getDecimals(h, cache)
|
amount := strconv.FormatInt(bal.Balance, 10)
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
amount := amountToString(bal.Balance, dec)
|
|
||||||
bs.Balances = append(bs.Balances, result.NEP5Balance{
|
bs.Balances = append(bs.Balances, result.NEP5Balance{
|
||||||
Asset: h,
|
Asset: h,
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
|
@ -606,20 +598,17 @@ func (s *Server) getNEP5Transfers(ps request.Params) (interface{}, *response.Err
|
||||||
Sent: []result.NEP5Transfer{},
|
Sent: []result.NEP5Transfer{},
|
||||||
}
|
}
|
||||||
lg := s.chain.GetNEP5TransferLog(u)
|
lg := s.chain.GetNEP5TransferLog(u)
|
||||||
cache := make(map[util.Uint160]int64)
|
|
||||||
err = lg.ForEach(func(tr *state.NEP5Transfer) error {
|
err = lg.ForEach(func(tr *state.NEP5Transfer) error {
|
||||||
transfer := result.NEP5Transfer{
|
transfer := result.NEP5Transfer{
|
||||||
Timestamp: tr.Timestamp,
|
Timestamp: tr.Timestamp,
|
||||||
Asset: tr.Asset,
|
Asset: tr.Asset,
|
||||||
Index: tr.Block,
|
Index: tr.Block,
|
||||||
TxHash: tr.Tx,
|
TxHash: tr.Tx,
|
||||||
}
|
|
||||||
d, err := s.getDecimals(tr.Asset, cache)
|
NotifyIndex: tr.Index,
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
if tr.Amount > 0 { // token was received
|
if tr.Amount > 0 { // token was received
|
||||||
transfer.Amount = amountToString(tr.Amount, d)
|
transfer.Amount = strconv.FormatInt(tr.Amount, 10)
|
||||||
if !tr.From.Equals(util.Uint160{}) {
|
if !tr.From.Equals(util.Uint160{}) {
|
||||||
transfer.Address = address.Uint160ToString(tr.From)
|
transfer.Address = address.Uint160ToString(tr.From)
|
||||||
}
|
}
|
||||||
|
@ -627,7 +616,7 @@ func (s *Server) getNEP5Transfers(ps request.Params) (interface{}, *response.Err
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
transfer.Amount = amountToString(-tr.Amount, d)
|
transfer.Amount = strconv.FormatInt(-tr.Amount, 10)
|
||||||
if !tr.To.Equals(util.Uint160{}) {
|
if !tr.To.Equals(util.Uint160{}) {
|
||||||
transfer.Address = address.Uint160ToString(tr.To)
|
transfer.Address = address.Uint160ToString(tr.To)
|
||||||
}
|
}
|
||||||
|
@ -640,63 +629,6 @@ func (s *Server) getNEP5Transfers(ps request.Params) (interface{}, *response.Err
|
||||||
return bs, nil
|
return bs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func amountToString(amount int64, decimals int64) string {
|
|
||||||
if decimals == 0 {
|
|
||||||
return strconv.FormatInt(amount, 10)
|
|
||||||
}
|
|
||||||
pow := int64(math.Pow10(int(decimals)))
|
|
||||||
q := amount / pow
|
|
||||||
r := amount % pow
|
|
||||||
if r == 0 {
|
|
||||||
return strconv.FormatInt(q, 10)
|
|
||||||
}
|
|
||||||
fs := fmt.Sprintf("%%d.%%0%dd", decimals)
|
|
||||||
return fmt.Sprintf(fs, q, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) getDecimals(h util.Uint160, cache map[util.Uint160]int64) (int64, *response.Error) {
|
|
||||||
if d, ok := cache[h]; ok {
|
|
||||||
return d, nil
|
|
||||||
}
|
|
||||||
m, err := s.chain.GetNEP5Metadata(h)
|
|
||||||
if err == nil {
|
|
||||||
cache[h] = m.Decimals
|
|
||||||
return m.Decimals, nil
|
|
||||||
}
|
|
||||||
script, err := request.CreateFunctionInvocationScript(h, request.Params{
|
|
||||||
{
|
|
||||||
Type: request.StringT,
|
|
||||||
Value: "decimals",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Type: request.ArrayT,
|
|
||||||
Value: []request.Param{},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return 0, response.NewInternalServerError("Can't create script", err)
|
|
||||||
}
|
|
||||||
res := s.runScriptInVM(script)
|
|
||||||
if res == nil || res.State != "HALT" || len(res.Stack) == 0 {
|
|
||||||
return 0, response.NewInternalServerError("execution error", errors.New("no result"))
|
|
||||||
}
|
|
||||||
|
|
||||||
var d int64
|
|
||||||
switch item := res.Stack[len(res.Stack)-1]; item.Type {
|
|
||||||
case smartcontract.IntegerType:
|
|
||||||
d = item.Value.(int64)
|
|
||||||
case smartcontract.ByteArrayType:
|
|
||||||
d = emit.BytesToInt(item.Value.([]byte)).Int64()
|
|
||||||
default:
|
|
||||||
return 0, response.NewInternalServerError("invalid result", errors.New("not an integer"))
|
|
||||||
}
|
|
||||||
if d < 0 {
|
|
||||||
return 0, response.NewInternalServerError("incorrect result", errors.New("negative result"))
|
|
||||||
}
|
|
||||||
cache[h] = d
|
|
||||||
return d, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) getProof(ps request.Params) (interface{}, *response.Error) {
|
func (s *Server) getProof(ps request.Params) (interface{}, *response.Error) {
|
||||||
root, err := ps.Value(0).GetUint256()
|
root, err := ps.Value(0).GetUint256()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -447,25 +447,25 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
"getblockheader": {
|
"getblockheader": {
|
||||||
{
|
{
|
||||||
name: "positive, no verbose",
|
name: "positive, no verbose",
|
||||||
params: `["eff4bb259b1d8bce877f132cbbdee7697c8fcf10154a16faaec4e71410c270c5"]`,
|
params: `["ac8239ca86a56ea02c66bc22c17bad194dd35d4e6391359435ab0a04af115fdf"]`,
|
||||||
result: func(e *executor) interface{} {
|
result: func(e *executor) interface{} {
|
||||||
expected := "00000000999086db552ba8f84734bddca55b25a8d3d8c5f866f941209169c38d35376e995f2f29c4685140d85073fec705089706553eae4de3c95d9d8d425af36e597ee633ff165f010000005704000000000000be48d3a3f5d10013ab9ffee489706078714f1ea201fd040140867ab10b2312fba2d9324f329936ccc938ba9f1ccfa5608b9ad4683ccafab9f1934b4e5a2ac784b97de02e12e97c20f159080cbd01493d0c77ddb184e18a0dbe40464ad05fa90bedfbae29b517532dc913dd1a0042801218b111d1cfb205ca2631b9246c28610055773209b0f82409b7218a0fbd1aa281b446edac31b87bd23b39404b87fef7696d42a32da3dfdcaa25cbb2db434a461bcadb5c91b3f078ab2cba960b5dad2d25b8c8423cf8574a4598fd7608f321d075a30e6327425e96a5cb306140d3527a08477ba441f2ba46256ff0d691c4bef0af1e8b80d65be9b0a5f350b15d130651725ab11bd1581a4ddfbc2486784a5057f727ea2d7d079d50153be17ce78b532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae00"
|
expected := "00000000999086db552ba8f84734bddca55b25a8d3d8c5f866f941209169c38d35376e995f2f29c4685140d85073fec705089706553eae4de3c95d9d8d425af36e597ee6bdc2275f010000005704000000000000be48d3a3f5d10013ab9ffee489706078714f1ea201fd040140e2ce9b2936c858ec8d8e2ae0dc3e1d924700efb44eecfccc6a7de134ff9b7505edf3e536fe6810f5ce585f6a2976b6bcf9b52addd2234ab73a063a7f52c07988401f91f717a3a386441d05a5c64a4e834299fd56d4f86c8e0eafc4d91e7e013d14a4eaff4d113aef76dedd93c326e9fe9f81e2ee0995ac20f87d56ef7c23bbea39400cf601281f67a69119fad0ef04e5c600b602ba36a490b1e32f006a9135bc5cb4359b855202680a7a07c03d16404738bbf7253c22013f67b2cc2a2a47640b3a63404cd3181b886fe64cf01caad4b4aa0c70587bd0fbcbc2d9cdd15bbc11878159a0da7341be6d06627e614d9e48529c7c96d4b9a4a56aca4fa118f1b49c2789e82b8b532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae00"
|
||||||
return &expected
|
return &expected
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "positive, verbose 0",
|
name: "positive, verbose 0",
|
||||||
params: `["eff4bb259b1d8bce877f132cbbdee7697c8fcf10154a16faaec4e71410c270c5", 0]`,
|
params: `["ac8239ca86a56ea02c66bc22c17bad194dd35d4e6391359435ab0a04af115fdf", 0]`,
|
||||||
result: func(e *executor) interface{} {
|
result: func(e *executor) interface{} {
|
||||||
expected := "00000000999086db552ba8f84734bddca55b25a8d3d8c5f866f941209169c38d35376e995f2f29c4685140d85073fec705089706553eae4de3c95d9d8d425af36e597ee633ff165f010000005704000000000000be48d3a3f5d10013ab9ffee489706078714f1ea201fd040140867ab10b2312fba2d9324f329936ccc938ba9f1ccfa5608b9ad4683ccafab9f1934b4e5a2ac784b97de02e12e97c20f159080cbd01493d0c77ddb184e18a0dbe40464ad05fa90bedfbae29b517532dc913dd1a0042801218b111d1cfb205ca2631b9246c28610055773209b0f82409b7218a0fbd1aa281b446edac31b87bd23b39404b87fef7696d42a32da3dfdcaa25cbb2db434a461bcadb5c91b3f078ab2cba960b5dad2d25b8c8423cf8574a4598fd7608f321d075a30e6327425e96a5cb306140d3527a08477ba441f2ba46256ff0d691c4bef0af1e8b80d65be9b0a5f350b15d130651725ab11bd1581a4ddfbc2486784a5057f727ea2d7d079d50153be17ce78b532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae00"
|
expected := "00000000999086db552ba8f84734bddca55b25a8d3d8c5f866f941209169c38d35376e995f2f29c4685140d85073fec705089706553eae4de3c95d9d8d425af36e597ee6bdc2275f010000005704000000000000be48d3a3f5d10013ab9ffee489706078714f1ea201fd040140e2ce9b2936c858ec8d8e2ae0dc3e1d924700efb44eecfccc6a7de134ff9b7505edf3e536fe6810f5ce585f6a2976b6bcf9b52addd2234ab73a063a7f52c07988401f91f717a3a386441d05a5c64a4e834299fd56d4f86c8e0eafc4d91e7e013d14a4eaff4d113aef76dedd93c326e9fe9f81e2ee0995ac20f87d56ef7c23bbea39400cf601281f67a69119fad0ef04e5c600b602ba36a490b1e32f006a9135bc5cb4359b855202680a7a07c03d16404738bbf7253c22013f67b2cc2a2a47640b3a63404cd3181b886fe64cf01caad4b4aa0c70587bd0fbcbc2d9cdd15bbc11878159a0da7341be6d06627e614d9e48529c7c96d4b9a4a56aca4fa118f1b49c2789e82b8b532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae00"
|
||||||
return &expected
|
return &expected
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "positive, verbose !=0",
|
name: "positive, verbose !=0",
|
||||||
params: `["eff4bb259b1d8bce877f132cbbdee7697c8fcf10154a16faaec4e71410c270c5", 2]`,
|
params: `["ac8239ca86a56ea02c66bc22c17bad194dd35d4e6391359435ab0a04af115fdf", 2]`,
|
||||||
result: func(e *executor) interface{} {
|
result: func(e *executor) interface{} {
|
||||||
hash, err := util.Uint256DecodeStringLE("eff4bb259b1d8bce877f132cbbdee7697c8fcf10154a16faaec4e71410c270c5")
|
hash, err := util.Uint256DecodeStringLE("ac8239ca86a56ea02c66bc22c17bad194dd35d4e6391359435ab0a04af115fdf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("can not decode hash parameter")
|
panic("can not decode hash parameter")
|
||||||
}
|
}
|
||||||
|
@ -497,7 +497,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid verbose type",
|
name: "invalid verbose type",
|
||||||
params: `["eff4bb259b1d8bce877f132cbbdee7697c8fcf10154a16faaec4e71410c270c5", true]`,
|
params: `["ac8239ca86a56ea02c66bc22c17bad194dd35d4e6391359435ab0a04af115fdf", true]`,
|
||||||
fail: true,
|
fail: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -889,7 +889,7 @@ var rpcTestCases = map[string][]rpcTestCase{
|
||||||
{
|
{
|
||||||
name: "positive",
|
name: "positive",
|
||||||
// If you are planning to modify test chain from `testblocks.acc`, please, update param value
|
// If you are planning to modify test chain from `testblocks.acc`, please, update param value
|
||||||
params: `["00000000c09fa5d15c48fc4d444a5cd103cbcfc17d7f336a9470342050a0d543c50e4603edb908054ac1409be5f77d5369c6e03490b2f6676d68d0b3370f8159e0fdadf90500175fd30000005704000000000000be48d3a3f5d10013ab9ffee489706078714f1ea201fd04014020f6f25257442110f3768ccff694b6f35c46a92859445f80cc57938a69b91bb7c23d1b87eab2e1a2c1fff14d264f2017baefc0d5c0ae586b203782fdd0f5a43d40b885005b735818d30294c5a477c1b736eac396be90a0f741511911efdd76fa47671bd02fa4161a443f84e02639d5ffbc20a341836cbc224a5471afbd89b4e82b40f089b04230dd5f0e872b2b1bfa12120481f0a79b110221a325d00101d6558c38888dcc0cc78f911d6037dfe7a41d1befeb9e055adf80597a0c4fca8fe8f0bb2440d6eb1075244c49cf785e093a60db3532acc7387e723d70562fd9ac74477b149047c6a09909c146906d2ac6c430fbfaead3c151ffa8a31b20db18e7ee43b1e22f8b532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae0100000000000000000000"]`,
|
params: `["00000000cd1bab8dadfbe297367aa85d77b9b31ea3e4c4a09285eca299fd124dec280dc9edb908054ac1409be5f77d5369c6e03490b2f6676d68d0b3370f8159e0fdadf98fc3275fd30000005704000000000000be48d3a3f5d10013ab9ffee489706078714f1ea201fd0401401dfd7f28a8c86acc58691d48db403ec29dcc342a0caf0f0ac4ee0329a94772ef05065c8c60921d8931d249b96b19a6059836fd489c8f55bce5e0ff94bc333e19400200f5f0b1c0eafdf41d30277004d987413cac71cc8fc5c73ba23274a18265d63e58fbc94f0118b9fa40411a0f75e478bccf52a8ab885881c443a69d56797f82409ee263f7699cb7b2c73955345a3354410322cad43a197de7138ef37e0fb1061e43cd907d1da725ca5a658babcfb23ed87064b639979b97b95686b0cc58d6d729403fa7fbe626bd60f452fd812ea2cefe81ee4bb374103a28dfe81d385c2d2c9925af3fd32d2868d7321db5b025e7ddf6ab27ac6d37fdfbbe3bae858fd4129128498b532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae0100000000000000000000"]`,
|
||||||
result: func(e *executor) interface{} {
|
result: func(e *executor) interface{} {
|
||||||
v := true
|
v := true
|
||||||
return &v
|
return &v
|
||||||
|
@ -1153,7 +1153,7 @@ func checkNep5Balances(t *testing.T, e *executor, acc interface{}) {
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.Equal(t, "AKkkumHbBipZ46UMZJoFynJMXzSRnBvKcs", res.Address)
|
require.Equal(t, "AKkkumHbBipZ46UMZJoFynJMXzSRnBvKcs", res.Address)
|
||||||
require.Equal(t, 1, len(res.Balances))
|
require.Equal(t, 1, len(res.Balances))
|
||||||
require.Equal(t, "8.80", res.Balances[0].Amount)
|
require.Equal(t, "880", res.Balances[0].Amount)
|
||||||
require.Equal(t, testContractHash, res.Balances[0].Asset.StringLE())
|
require.Equal(t, testContractHash, res.Balances[0].Asset.StringLE())
|
||||||
require.Equal(t, uint32(210), res.Balances[0].LastUpdated)
|
require.Equal(t, uint32(210), res.Balances[0].LastUpdated)
|
||||||
}
|
}
|
||||||
|
@ -1169,17 +1169,24 @@ func checkNep5Transfers(t *testing.T, e *executor, acc interface{}) {
|
||||||
assetHashOld, err := util.Uint160DecodeStringLE(testContractHashOld)
|
assetHashOld, err := util.Uint160DecodeStringLE(testContractHashOld)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, 2, len(res.Received))
|
require.Equal(t, 3, len(res.Received))
|
||||||
require.Equal(t, "10", res.Received[0].Amount)
|
require.Equal(t, "1000", res.Received[0].Amount)
|
||||||
require.Equal(t, assetHashOld, res.Received[0].Asset)
|
require.Equal(t, assetHashOld, res.Received[0].Asset)
|
||||||
require.Equal(t, address.Uint160ToString(assetHashOld), res.Received[0].Address)
|
require.Equal(t, address.Uint160ToString(assetHashOld), res.Received[0].Address)
|
||||||
|
|
||||||
require.Equal(t, "0.03", res.Received[1].Amount)
|
require.Equal(t, "2", res.Received[1].Amount)
|
||||||
require.Equal(t, assetHash, res.Received[1].Asset)
|
require.Equal(t, assetHash, res.Received[1].Asset)
|
||||||
require.Equal(t, "AWLYWXB8C9Lt1nHdDZJnC5cpYJjgRDLk17", res.Received[1].Address)
|
require.Equal(t, "AWLYWXB8C9Lt1nHdDZJnC5cpYJjgRDLk17", res.Received[1].Address)
|
||||||
|
require.Equal(t, uint32(0), res.Received[1].NotifyIndex)
|
||||||
|
|
||||||
|
require.Equal(t, "1", res.Received[2].Amount)
|
||||||
|
require.Equal(t, assetHash, res.Received[2].Asset)
|
||||||
|
require.Equal(t, "AWLYWXB8C9Lt1nHdDZJnC5cpYJjgRDLk17", res.Received[2].Address)
|
||||||
|
require.Equal(t, uint32(1), res.Received[2].NotifyIndex)
|
||||||
|
|
||||||
require.Equal(t, 1, len(res.Sent))
|
require.Equal(t, 1, len(res.Sent))
|
||||||
require.Equal(t, "1.23", res.Sent[0].Amount)
|
require.Equal(t, "123", res.Sent[0].Amount)
|
||||||
require.Equal(t, assetHashOld, res.Sent[0].Asset)
|
require.Equal(t, assetHashOld, res.Sent[0].Asset)
|
||||||
require.Equal(t, "AWLYWXB8C9Lt1nHdDZJnC5cpYJjgRDLk17", res.Sent[0].Address)
|
require.Equal(t, "AWLYWXB8C9Lt1nHdDZJnC5cpYJjgRDLk17", res.Sent[0].Address)
|
||||||
|
require.Equal(t, uint32(0), res.Sent[0].NotifyIndex)
|
||||||
}
|
}
|
||||||
|
|
BIN
pkg/rpc/server/testdata/testblocks.acc
vendored
BIN
pkg/rpc/server/testdata/testblocks.acc
vendored
Binary file not shown.
Loading…
Reference in a new issue