mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-27 15:42:54 +00:00
6b21ad9922
Everywhere including examples, external interop APIs, bindings generators code and in other valuable places. A couple of `interface{}` usages are intentionally left in the CHANGELOG.md, documentation and tests.
86 lines
2 KiB
Go
86 lines
2 KiB
Go
package oracle
|
|
|
|
import (
|
|
"errors"
|
|
"math/big"
|
|
"testing"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type testAct struct {
|
|
err error
|
|
res *result.Invoke
|
|
tx *transaction.Transaction
|
|
txh util.Uint256
|
|
vub uint32
|
|
}
|
|
|
|
func (t *testAct) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) {
|
|
return t.res, t.err
|
|
}
|
|
func (t *testAct) MakeCall(contract util.Uint160, method string, params ...any) (*transaction.Transaction, error) {
|
|
return t.tx, t.err
|
|
}
|
|
func (t *testAct) MakeUnsignedCall(contract util.Uint160, method string, attrs []transaction.Attribute, params ...any) (*transaction.Transaction, error) {
|
|
return t.tx, t.err
|
|
}
|
|
func (t *testAct) SendCall(contract util.Uint160, method string, params ...any) (util.Uint256, uint32, error) {
|
|
return t.txh, t.vub, t.err
|
|
}
|
|
|
|
func TestReader(t *testing.T) {
|
|
ta := new(testAct)
|
|
ora := NewReader(ta)
|
|
|
|
ta.err = errors.New("")
|
|
_, err := ora.GetPrice()
|
|
require.Error(t, err)
|
|
|
|
ta.err = nil
|
|
ta.res = &result.Invoke{
|
|
State: "HALT",
|
|
Stack: []stackitem.Item{
|
|
stackitem.Make(42),
|
|
},
|
|
}
|
|
price, err := ora.GetPrice()
|
|
require.NoError(t, err)
|
|
require.Equal(t, big.NewInt(42), price)
|
|
}
|
|
|
|
func TestPriceSetter(t *testing.T) {
|
|
ta := new(testAct)
|
|
ora := New(ta)
|
|
|
|
big42 := big.NewInt(42)
|
|
|
|
ta.err = errors.New("")
|
|
_, _, err := ora.SetPrice(big42)
|
|
require.Error(t, err)
|
|
_, err = ora.SetPriceTransaction(big42)
|
|
require.Error(t, err)
|
|
_, err = ora.SetPriceUnsigned(big42)
|
|
require.Error(t, err)
|
|
|
|
ta.err = nil
|
|
ta.txh = util.Uint256{1, 2, 3}
|
|
ta.vub = 42
|
|
ta.tx = transaction.New([]byte{1, 2, 3}, 100500)
|
|
|
|
h, vub, err := ora.SetPrice(big42)
|
|
require.NoError(t, err)
|
|
require.Equal(t, ta.txh, h)
|
|
require.Equal(t, ta.vub, vub)
|
|
|
|
tx, err := ora.SetPriceTransaction(big42)
|
|
require.NoError(t, err)
|
|
require.Equal(t, ta.tx, tx)
|
|
tx, err = ora.SetPriceUnsigned(big42)
|
|
require.NoError(t, err)
|
|
require.Equal(t, ta.tx, tx)
|
|
}
|