github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/core/native/policy_test.go (about) 1 package native_test 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/nspcc-dev/neo-go/pkg/core/interop" 8 "github.com/nspcc-dev/neo-go/pkg/core/native" 9 "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" 10 "github.com/nspcc-dev/neo-go/pkg/neotest" 11 "github.com/nspcc-dev/neo-go/pkg/neotest/chain" 12 "github.com/stretchr/testify/require" 13 ) 14 15 func TestPolicy_FeePerByte(t *testing.T) { 16 bc, _, _ := chain.NewMulti(t) 17 18 t.Run("get, internal method", func(t *testing.T) { 19 n := bc.FeePerByte() 20 require.Equal(t, 1000, int(n)) 21 }) 22 } 23 24 func TestPolicy_ExecFeeFactor(t *testing.T) { 25 bc, _, _ := chain.NewMulti(t) 26 27 t.Run("get, internal method", func(t *testing.T) { 28 n := bc.GetBaseExecFee() 29 require.EqualValues(t, interop.DefaultBaseExecFee, n) 30 }) 31 } 32 33 func TestPolicy_StoragePrice(t *testing.T) { 34 bc, validators, committee := chain.NewMulti(t) 35 e := neotest.NewExecutor(t, bc, validators, committee) 36 37 t.Run("get, internal method", func(t *testing.T) { 38 e.AddNewBlock(t) // avoid default value got from Blockchain. 39 40 n := bc.GetStoragePrice() 41 require.Equal(t, int64(native.DefaultStoragePrice), n) 42 }) 43 } 44 45 func TestPolicy_BlockedAccounts(t *testing.T) { 46 bc, validators, committee := chain.NewMulti(t) 47 e := neotest.NewExecutor(t, bc, validators, committee) 48 policyHash := e.NativeHash(t, nativenames.Policy) 49 50 policySuperInvoker := e.NewInvoker(policyHash, validators, committee) 51 unlucky := e.NewAccount(t, 5_0000_0000) 52 policyUnluckyInvoker := e.NewInvoker(policyHash, unlucky) 53 54 // Block unlucky account. 55 policySuperInvoker.Invoke(t, true, "blockAccount", unlucky.ScriptHash()) 56 57 // Transaction from blocked account shouldn't be accepted. 58 t.Run("isBlocked, internal method", func(t *testing.T) { 59 tx := policyUnluckyInvoker.PrepareInvoke(t, "getStoragePrice") 60 b := e.NewUnsignedBlock(t, tx) 61 e.SignBlock(b) 62 expectedErr := fmt.Sprintf("transaction %s failed to verify: not allowed by policy: account %s is blocked", tx.Hash().StringLE(), unlucky.ScriptHash().StringLE()) 63 err := e.Chain.AddBlock(b) 64 require.Error(t, err) 65 require.Equal(t, expectedErr, err.Error()) 66 }) 67 }