neoneo-go/pkg/core/native_policy_test.go

68 lines
2 KiB
Go
Raw Normal View History

2022-03-11 14:47:59 +00:00
package core_test
import (
2022-03-11 14:47:59 +00:00
"fmt"
"testing"
"github.com/nspcc-dev/neo-go/pkg/core/interop"
"github.com/nspcc-dev/neo-go/pkg/core/native"
2022-03-11 14:47:59 +00:00
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
"github.com/nspcc-dev/neo-go/pkg/neotest"
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
"github.com/stretchr/testify/require"
)
2022-03-11 14:47:59 +00:00
func TestPolicy_FeePerByte(t *testing.T) {
bc, _, _ := chain.NewMulti(t)
t.Run("get, internal method", func(t *testing.T) {
2022-03-11 14:47:59 +00:00
n := bc.FeePerByte()
require.Equal(t, 1000, int(n))
})
}
2022-03-11 14:47:59 +00:00
func TestPolicy_ExecFeeFactor(t *testing.T) {
bc, _, _ := chain.NewMulti(t)
t.Run("get, internal method", func(t *testing.T) {
2022-03-11 14:47:59 +00:00
n := bc.GetBaseExecFee()
require.EqualValues(t, interop.DefaultBaseExecFee, n)
})
}
2022-03-11 14:47:59 +00:00
func TestPolicy_StoragePrice(t *testing.T) {
bc, validators, committee := chain.NewMulti(t)
e := neotest.NewExecutor(t, bc, validators, committee)
t.Run("get, internal method", func(t *testing.T) {
2022-03-11 14:47:59 +00:00
e.AddNewBlock(t) // avoid default value got from Blockchain.
n := bc.GetStoragePrice()
require.Equal(t, int64(native.DefaultStoragePrice), n)
})
}
2022-03-11 14:47:59 +00:00
func TestPolicy_BlockedAccounts(t *testing.T) {
bc, validators, committee := chain.NewMulti(t)
e := neotest.NewExecutor(t, bc, validators, committee)
policyHash := e.NativeHash(t, nativenames.Policy)
policySuperInvoker := e.NewInvoker(policyHash, validators, committee)
unlucky := e.NewAccount(t, 5_0000_0000)
policyUnluckyInvoker := e.NewInvoker(policyHash, unlucky)
// Block unlucky account.
policySuperInvoker.Invoke(t, true, "blockAccount", unlucky.ScriptHash())
2021-01-21 12:05:15 +00:00
2022-03-11 14:47:59 +00:00
// Transaction from blocked account shouldn't be accepted.
2020-10-21 12:51:59 +00:00
t.Run("isBlocked, internal method", func(t *testing.T) {
2022-03-11 14:47:59 +00:00
tx := policyUnluckyInvoker.PrepareInvoke(t, "getStoragePrice")
b := e.NewUnsignedBlock(t, tx)
e.SignBlock(b)
expectedErr := fmt.Sprintf("transaction %s failed to verify: not allowed by policy: account %s is blocked", tx.Hash().StringLE(), unlucky.ScriptHash().StringLE())
err := e.Chain.AddBlock(b)
require.Error(t, err)
require.Equal(t, expectedErr, err.Error())
})
}