From 1031b74b5b9bbf1f3d085e71e2569eba6a70cf21 Mon Sep 17 00:00:00 2001 From: Nikolay Eskov Date: Fri, 17 Jun 2022 04:25:54 +0300 Subject: [PATCH] Fixed tests in 'ride' package. Refactored a bit. --- pkg/ride/environment.go | 13 +- pkg/ride/functions_proto_test.go | 19 +- pkg/ride/tree_evaluation_test.go | 301 ++++++++++++------------------- 3 files changed, 132 insertions(+), 201 deletions(-) diff --git a/pkg/ride/environment.go b/pkg/ride/environment.go index 4d4d782d9..27f437184 100644 --- a/pkg/ride/environment.go +++ b/pkg/ride/environment.go @@ -14,6 +14,13 @@ var ( errDeletedEntry = errors.New("entry has been deleted") ) +var ( + libV2CheckMessageLength = func(int) bool { return true } + libV3CheckMessageLength = func(l int) bool { + return l <= maxMessageLength + } +) + type lastTwoInvokeComplexities [2]int func (l *lastTwoInvokeComplexities) pushComplexity(complexity int) { @@ -1107,7 +1114,7 @@ func NewEnvironment(scheme proto.Scheme, state types.SmartState, internalPayment sch: scheme, st: state, h: rideInt(height), - check: func(int) bool { return true }, // By default, for versions below 2 there was no check, always ok. + check: libV2CheckMessageLength, // By default, for versions below 2 there was no check, always ok. takeStr: func(s string, n int) rideString { panic("function 'takeStr' was not initialized") }, validatePaymentsAfter: internalPaymentsValidationHeight, }, nil @@ -1213,9 +1220,7 @@ func (e *EvaluationEnvironment) ChooseTakeString(isRideV5 bool) { func (e *EvaluationEnvironment) ChooseSizeCheck(v ast.LibraryVersion) { e.ver = v if v > ast.LibV2 { - e.check = func(l int) bool { - return l <= maxMessageLength - } + e.check = libV3CheckMessageLength } } diff --git a/pkg/ride/functions_proto_test.go b/pkg/ride/functions_proto_test.go index b58ea1591..c91c94f30 100644 --- a/pkg/ride/functions_proto_test.go +++ b/pkg/ride/functions_proto_test.go @@ -19,16 +19,17 @@ import ( ) var ( - v2check = func(int) bool { - return true - } - v3check = func(size int) bool { - return size <= maxMessageLength - } + trueFn = func() bool { return true } + falseFn = func() bool { return false } +) + +var ( + v2check = libV2CheckMessageLength + v3check = libV3CheckMessageLength v5takeString = takeRideString - noRideV6 = func() bool { - return false - } + yesRideV5 = trueFn + yesRideV6 = trueFn + noRideV6 = falseFn ) func TestAddressFromString(t *testing.T) { diff --git a/pkg/ride/tree_evaluation_test.go b/pkg/ride/tree_evaluation_test.go index 1323b0315..36fc71e1b 100644 --- a/pkg/ride/tree_evaluation_test.go +++ b/pkg/ride/tree_evaluation_test.go @@ -28,9 +28,7 @@ var ( }, rideV6ActivatedFunc: noRideV6, } - isProtobufTx = func() bool { - return true - } + isProtobufTx = trueFn ) func TestSimpleScriptEvaluation(t *testing.T) { @@ -176,10 +174,8 @@ func TestFunctionsEvaluation(t *testing.T) { } return obj }, - validateInternalPaymentsFunc: func() bool { - return false - }, - rideV6ActivatedFunc: noRideV6, + validateInternalPaymentsFunc: falseFn, + rideV6ActivatedFunc: noRideV6, } envWithDataTX := &mockRideEnvironment{ transactionFunc: func() rideObject { @@ -1087,16 +1083,10 @@ var envDappFromDapp = &mockRideEnvironment{ timestampFunc: func() uint64 { return 1564703444249 }, - blockV5ActivatedFunc: func() bool { - return true - }, - rideV5ActivatedFunc: func() bool { - return true - }, - rideV6ActivatedFunc: noRideV6, - validateInternalPaymentsFunc: func() bool { - return true - }, + blockV5ActivatedFunc: trueFn, + rideV5ActivatedFunc: yesRideV5, + rideV6ActivatedFunc: noRideV6, + validateInternalPaymentsFunc: trueFn, internalPaymentsValidationHeightFunc: func() uint64 { return 0 }, @@ -1115,9 +1105,7 @@ func tearDownDappFromDapp() { addressCallable = proto.WavesAddress{} addrPK = crypto.PublicKey{} addressCallablePK = crypto.PublicKey{} - envDappFromDapp.rideV5ActivatedFunc = func() bool { - return true - } + envDappFromDapp.rideV5ActivatedFunc = trueFn envDappFromDapp.rideV6ActivatedFunc = noRideV6 thisAddress = proto.WavesAddress{} @@ -1545,9 +1533,7 @@ func TestInvokeBalanceValidationV6(t *testing.T) { thisAddress = addr env := envDappFromDapp - env.rideV6ActivatedFunc = func() bool { - return true - } + env.rideV6ActivatedFunc = trueFn _, tree := parseBase64Script(t, firstScript) @@ -1704,9 +1690,7 @@ func TestInvokeFailedBalanceValidationV6(t *testing.T) { thisAddress = addr env := envDappFromDapp - env.rideV6ActivatedFunc = func() bool { - return true - } + env.rideV6ActivatedFunc = trueFn _, tree := parseBase64Script(t, firstScript) @@ -5685,10 +5669,8 @@ func TestMathDApp(t *testing.T) { require.NoError(t, err) return obj }, - validateInternalPaymentsFunc: func() bool { - return false - }, - rideV6ActivatedFunc: noRideV6, + validateInternalPaymentsFunc: falseFn, + rideV6ActivatedFunc: noRideV6, } code := "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" @@ -7156,13 +7138,9 @@ func TestOriginCaller(t *testing.T) { maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, - validateInternalPaymentsFunc: func() bool { - return true - }, - blockV5ActivatedFunc: func() bool { - return true - }, - isProtobufTxFunc: isProtobufTx, + validateInternalPaymentsFunc: trueFn, + blockV5ActivatedFunc: trueFn, + isProtobufTxFunc: isProtobufTx, } mockState := &MockSmartState{ @@ -7327,17 +7305,14 @@ func TestInternalPaymentsValidationFailure(t *testing.T) { setInvocationFunc: func(inv rideObject) { testInv = inv }, - blockV5ActivatedFunc: func() bool { - return true - }, - rideV6ActivatedFunc: noRideV6, + blockV5ActivatedFunc: trueFn, + rideV5ActivatedFunc: yesRideV5, + rideV6ActivatedFunc: noRideV6, setNewDAppAddressFunc: func(address proto.WavesAddress) { testDAppAddress = address testState.cle = rideAddress(address) }, - validateInternalPaymentsFunc: func() bool { - return true - }, + validateInternalPaymentsFunc: trueFn, maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, @@ -7410,9 +7385,7 @@ func TestInternalPaymentsValidationFailure(t *testing.T) { require.Error(t, err) // Turning off internal payments validation - env.validateInternalPaymentsFunc = func() bool { - return false - } + env.validateInternalPaymentsFunc = falseFn testInv, err = invocationToObject(5, proto.MainNetScheme, tx) require.NoError(t, err) testDAppAddress = dApp1 @@ -7503,17 +7476,13 @@ func TestAliasesInInvokes(t *testing.T) { invocationFunc: func() rideObject { return testInv }, - blockV5ActivatedFunc: func() bool { - return true - }, + blockV5ActivatedFunc: trueFn, rideV6ActivatedFunc: noRideV6, checkMessageLengthFunc: v3check, setInvocationFunc: func(inv rideObject) { testInv = inv }, - validateInternalPaymentsFunc: func() bool { - return true - }, + validateInternalPaymentsFunc: trueFn, maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, @@ -7734,13 +7703,9 @@ func TestIssueAndTransferInInvoke(t *testing.T) { setInvocationFunc: func(inv rideObject) { testInv = inv }, - blockV5ActivatedFunc: func() bool { - return true - }, - rideV6ActivatedFunc: noRideV6, - validateInternalPaymentsFunc: func() bool { - return true - }, + blockV5ActivatedFunc: trueFn, + rideV6ActivatedFunc: noRideV6, + validateInternalPaymentsFunc: trueFn, txIDFunc: func() rideType { return rideBytes(tx.ID.Bytes()) }, @@ -7923,22 +7888,17 @@ func TestTransferUnavailableFundsInInvoke(t *testing.T) { setInvocationFunc: func(inv rideObject) { testInv = inv }, - validateInternalPaymentsFunc: func() bool { - return true - }, + validateInternalPaymentsFunc: trueFn, txIDFunc: func() rideType { return rideBytes(tx.ID.Bytes()) }, maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, - blockV5ActivatedFunc: func() bool { - return true - }, - rideV6ActivatedFunc: func() bool { - return true - }, - isProtobufTxFunc: isProtobufTx, + blockV5ActivatedFunc: trueFn, + rideV5ActivatedFunc: yesRideV5, + rideV6ActivatedFunc: yesRideV6, + isProtobufTxFunc: isProtobufTx, } mockState := &MockSmartState{ @@ -8082,10 +8042,9 @@ func TestBurnAndFailOnTransferInInvokeAfterRideV6(t *testing.T) { thisFunc: func() rideType { return rideAddress(testDAppAddress) }, - blockV5ActivatedFunc: func() bool { - return true - }, - rideV6ActivatedFunc: noRideV6, + blockV5ActivatedFunc: trueFn, + rideV5ActivatedFunc: yesRideV5, + rideV6ActivatedFunc: noRideV6, transactionFunc: func() rideObject { obj, err := transactionToObject(proto.TestNetScheme, tx) require.NoError(t, err) @@ -8098,9 +8057,7 @@ func TestBurnAndFailOnTransferInInvokeAfterRideV6(t *testing.T) { setInvocationFunc: func(inv rideObject) { testInv = inv }, - validateInternalPaymentsFunc: func() bool { - return true - }, + validateInternalPaymentsFunc: trueFn, maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, @@ -8278,17 +8235,13 @@ func TestReissueInInvoke(t *testing.T) { setInvocationFunc: func(inv rideObject) { testInv = inv }, - validateInternalPaymentsFunc: func() bool { - return true - }, + validateInternalPaymentsFunc: trueFn, maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, - blockV5ActivatedFunc: func() bool { - return true - }, - rideV6ActivatedFunc: noRideV6, - isProtobufTxFunc: isProtobufTx, + blockV5ActivatedFunc: trueFn, + rideV6ActivatedFunc: noRideV6, + isProtobufTxFunc: isProtobufTx, } mockState := &MockSmartState{ @@ -8475,11 +8428,10 @@ func TestNegativePayments(t *testing.T) { maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, - blockV5ActivatedFunc: func() bool { - return true - }, - rideV6ActivatedFunc: noRideV6, - isProtobufTxFunc: isProtobufTx, + blockV5ActivatedFunc: trueFn, + rideV5ActivatedFunc: yesRideV5, + rideV6ActivatedFunc: noRideV6, + isProtobufTxFunc: isProtobufTx, } mockState := &MockSmartState{ @@ -8669,17 +8621,13 @@ func TestComplexityOverflow(t *testing.T) { setInvocationFunc: func(inv rideObject) { testInv = inv }, - validateInternalPaymentsFunc: func() bool { - return true - }, + validateInternalPaymentsFunc: trueFn, maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, - blockV5ActivatedFunc: func() bool { - return true - }, - rideV6ActivatedFunc: noRideV6, - isProtobufTxFunc: isProtobufTx, + blockV5ActivatedFunc: trueFn, + rideV6ActivatedFunc: noRideV6, + isProtobufTxFunc: isProtobufTx, libVersionFunc: func() ast.LibraryVersion { return ast.LibV5 }, @@ -8813,17 +8761,13 @@ func TestDateEntryPutAfterRemoval(t *testing.T) { setInvocationFunc: func(inv rideObject) { testInv = inv }, - validateInternalPaymentsFunc: func() bool { - return true - }, + validateInternalPaymentsFunc: trueFn, maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, - blockV5ActivatedFunc: func() bool { - return true - }, - rideV6ActivatedFunc: noRideV6, - isProtobufTxFunc: isProtobufTx, + blockV5ActivatedFunc: trueFn, + rideV6ActivatedFunc: noRideV6, + isProtobufTxFunc: isProtobufTx, libVersionFunc: func() ast.LibraryVersion { return ast.LibV5 }, @@ -8955,17 +8899,14 @@ func TestFailRejectMultiLevelInvokesBeforeRideV6(t *testing.T) { setInvocationFunc: func(inv rideObject) { testInv = inv }, - validateInternalPaymentsFunc: func() bool { - return true - }, + validateInternalPaymentsFunc: trueFn, maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, - blockV5ActivatedFunc: func() bool { - return true - }, - rideV6ActivatedFunc: noRideV6, - isProtobufTxFunc: isProtobufTx, + blockV5ActivatedFunc: trueFn, + rideV5ActivatedFunc: yesRideV5, + rideV6ActivatedFunc: noRideV6, + isProtobufTxFunc: isProtobufTx, libVersionFunc: func() ast.LibraryVersion { return ast.LibV5 }, @@ -9118,22 +9059,17 @@ func TestInvokeFailForRideV4(t *testing.T) { setInvocationFunc: func(inv rideObject) { testInv = inv }, - validateInternalPaymentsFunc: func() bool { - return true - }, + validateInternalPaymentsFunc: trueFn, txIDFunc: func() rideType { return rideBytes(tx.ID.Bytes()) }, maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, - blockV5ActivatedFunc: func() bool { - return true - }, - rideV6ActivatedFunc: func() bool { - return true - }, - isProtobufTxFunc: isProtobufTx, + blockV5ActivatedFunc: trueFn, + rideV5ActivatedFunc: yesRideV5, + rideV6ActivatedFunc: yesRideV6, + isProtobufTxFunc: isProtobufTx, } mockState := &MockSmartState{ @@ -9302,17 +9238,14 @@ func TestInvokeActionsCountRestrictionsV6ToV5Positive(t *testing.T) { invocationFunc: func() rideObject { return testInv }, - blockV5ActivatedFunc: func() bool { - return true - }, - rideV6ActivatedFunc: noRideV6, + blockV5ActivatedFunc: trueFn, + rideV5ActivatedFunc: yesRideV5, + rideV6ActivatedFunc: yesRideV6, checkMessageLengthFunc: v3check, setInvocationFunc: func(inv rideObject) { testInv = inv }, - validateInternalPaymentsFunc: func() bool { - return true - }, + validateInternalPaymentsFunc: trueFn, maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, @@ -9362,19 +9295,21 @@ func TestInvokeActionsCountRestrictionsV6ToV5Positive(t *testing.T) { return proto.WavesAddress{}, errors.Errorf("unexpected alias '%s'", alias.String()) } }, - NewestWavesBalanceFunc: func(account proto.Recipient) (uint64, error) { + NewestFullWavesBalanceFunc: func(account proto.Recipient) (*proto.FullWavesBalance, error) { + var available uint64 switch account.String() { case dApp1.String(): - return 0, nil + available = 0 case caller.String(): - return 0, nil + available = 0 case dApp2.String(): - return 100_000_000_000, nil + available = 100_000_000_000 case callee.String(): - return 100_000_000_000, nil + available = 100_000_000_000 default: - return 0, errors.Errorf("unexpected account '%s'", account.String()) + return nil, errors.Errorf("unexpected account '%s'", account.String()) } + return &proto.FullWavesBalance{Available: available}, nil }, } @@ -9548,17 +9483,14 @@ func TestInvokeActionsCountRestrictionsV6ToV5NestedPositive(t *testing.T) { invocationFunc: func() rideObject { return testInv }, - blockV5ActivatedFunc: func() bool { - return true - }, - rideV6ActivatedFunc: noRideV6, + blockV5ActivatedFunc: trueFn, + rideV5ActivatedFunc: yesRideV5, + rideV6ActivatedFunc: yesRideV6, checkMessageLengthFunc: v3check, setInvocationFunc: func(inv rideObject) { testInv = inv }, - validateInternalPaymentsFunc: func() bool { - return true - }, + validateInternalPaymentsFunc: trueFn, maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, @@ -9608,19 +9540,21 @@ func TestInvokeActionsCountRestrictionsV6ToV5NestedPositive(t *testing.T) { return proto.WavesAddress{}, errors.Errorf("unexpected alias '%s'", alias.String()) } }, - NewestWavesBalanceFunc: func(account proto.Recipient) (uint64, error) { + NewestFullWavesBalanceFunc: func(account proto.Recipient) (*proto.FullWavesBalance, error) { + var available uint64 switch account.String() { case dApp1.String(): - return 100_000_000_000, nil + available = 100_000_000_000 case caller.String(): - return 100_000_000_000, nil + available = 100_000_000_000 case dApp2.String(): - return 100_000_000_000, nil + available = 100_000_000_000 case callee.String(): - return 100_000_000_000, nil + available = 100_000_000_000 default: - return 0, errors.Errorf("unexpected account '%s'", account.String()) + return nil, errors.Errorf("unexpected account '%s'", account.String()) } + return &proto.FullWavesBalance{Available: available}, nil }, } @@ -9755,17 +9689,14 @@ func TestInvokeActionsCountRestrictionsV6ToV5OverflowNegative(t *testing.T) { invocationFunc: func() rideObject { return testInv }, - blockV5ActivatedFunc: func() bool { - return true - }, - rideV6ActivatedFunc: noRideV6, + blockV5ActivatedFunc: trueFn, + rideV5ActivatedFunc: yesRideV5, + rideV6ActivatedFunc: yesRideV6, checkMessageLengthFunc: v3check, setInvocationFunc: func(inv rideObject) { testInv = inv }, - validateInternalPaymentsFunc: func() bool { - return true - }, + validateInternalPaymentsFunc: trueFn, maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, @@ -9815,19 +9746,21 @@ func TestInvokeActionsCountRestrictionsV6ToV5OverflowNegative(t *testing.T) { return proto.WavesAddress{}, errors.Errorf("unexpected alias '%s'", alias.String()) } }, - NewestWavesBalanceFunc: func(account proto.Recipient) (uint64, error) { + NewestFullWavesBalanceFunc: func(account proto.Recipient) (*proto.FullWavesBalance, error) { + var available uint64 switch account.String() { case dApp1.String(): - return 0, nil + available = 0 case caller.String(): - return 0, nil + available = 0 case dApp2.String(): - return 100_000_000_000, nil + available = 100_000_000_000 case callee.String(): - return 100_000_000_000, nil + available = 100_000_000_000 default: - return 0, errors.Errorf("unexpected account '%s'", account.String()) + return nil, errors.Errorf("unexpected account '%s'", account.String()) } + return &proto.FullWavesBalance{Available: available}, nil }, } @@ -9970,17 +9903,14 @@ func TestInvokeActionsCountRestrictionsV6ToV5PNegative(t *testing.T) { invocationFunc: func() rideObject { return testInv }, - blockV5ActivatedFunc: func() bool { - return true - }, - rideV6ActivatedFunc: noRideV6, + blockV5ActivatedFunc: trueFn, + rideV5ActivatedFunc: yesRideV5, + rideV6ActivatedFunc: yesRideV6, checkMessageLengthFunc: v3check, setInvocationFunc: func(inv rideObject) { testInv = inv }, - validateInternalPaymentsFunc: func() bool { - return true - }, + validateInternalPaymentsFunc: trueFn, maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, @@ -10030,19 +9960,21 @@ func TestInvokeActionsCountRestrictionsV6ToV5PNegative(t *testing.T) { return proto.WavesAddress{}, errors.Errorf("unexpected alias '%s'", alias.String()) } }, - NewestWavesBalanceFunc: func(account proto.Recipient) (uint64, error) { + NewestFullWavesBalanceFunc: func(account proto.Recipient) (*proto.FullWavesBalance, error) { + var available uint64 switch account.String() { case dApp1.String(): - return 0, nil + available = 0 case caller.String(): - return 0, nil + available = 0 case dApp2.String(): - return 100_000_000_000, nil + available = 100_000_000_000 case callee.String(): - return 100_000_000_000, nil + available = 100_000_000_000 default: - return 0, errors.Errorf("unexpected account '%s'", account.String()) + return nil, errors.Errorf("unexpected account '%s'", account.String()) } + return &proto.FullWavesBalance{Available: available}, nil }, } @@ -10153,18 +10085,15 @@ func TestInvokeDappAttachedPaymentsLimitAfterV6(t *testing.T) { setInvocationFunc: func(inv rideObject) { testInv = inv }, - validateInternalPaymentsFunc: func() bool { - return true - }, + validateInternalPaymentsFunc: trueFn, txIDFunc: func() rideType { return rideBytes(tx.ID.Bytes()) }, maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, - blockV5ActivatedFunc: func() bool { - return true - }, + blockV5ActivatedFunc: trueFn, + rideV5ActivatedFunc: yesRideV5, rideV6ActivatedFunc: func() bool { return rideV6Activated }, @@ -10308,15 +10237,11 @@ func TestInvokeDappFromDappWithZeroPayments(t *testing.T) { setInvocationFunc: func(inv rideObject) { testInv = inv }, - validateInternalPaymentsFunc: func() bool { - return true - }, + validateInternalPaymentsFunc: trueFn, maxDataEntriesSizeFunc: func() int { return proto.MaxDataEntriesScriptActionsSizeInBytesV2 }, - blockV5ActivatedFunc: func() bool { - return true - }, + blockV5ActivatedFunc: trueFn, rideV6ActivatedFunc: func() bool { return rideV6Activated },