2022-03-11 14:47:59 +00:00
package core_test
2020-06-15 18:13:32 +00:00
import (
2022-03-11 14:47:59 +00:00
"fmt"
2020-06-15 18:13:32 +00:00
"testing"
2020-12-14 09:18:59 +00:00
"github.com/nspcc-dev/neo-go/pkg/core/interop"
2020-06-15 18:13:32 +00:00
"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"
2020-06-15 18:13:32 +00:00
"github.com/stretchr/testify/require"
)
2022-03-11 14:47:59 +00:00
func TestPolicy_FeePerByte ( t * testing . T ) {
bc , _ , _ := chain . NewMulti ( t )
2020-06-15 18:13:32 +00:00
t . Run ( "get, internal method" , func ( t * testing . T ) {
2022-03-11 14:47:59 +00:00
n := bc . FeePerByte ( )
2020-06-15 18:13:32 +00:00
require . Equal ( t , 1000 , int ( n ) )
} )
}
2022-03-11 14:47:59 +00:00
func TestPolicy_ExecFeeFactor ( t * testing . T ) {
bc , _ , _ := chain . NewMulti ( t )
2020-12-14 09:18:59 +00:00
t . Run ( "get, internal method" , func ( t * testing . T ) {
2022-03-11 14:47:59 +00:00
n := bc . GetBaseExecFee ( )
2020-12-14 09:18:59 +00:00
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 )
2020-12-14 09:41:23 +00:00
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 ( )
2021-02-02 15:46:43 +00:00
require . Equal ( t , int64 ( native . DefaultStoragePrice ) , n )
2020-12-14 09:41:23 +00:00
} )
}
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 ( ) )
2020-06-15 18:13:32 +00:00
} )
}