-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathforbidden_opcodes_test.go
More file actions
63 lines (55 loc) · 2.08 KB
/
forbidden_opcodes_test.go
File metadata and controls
63 lines (55 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package hostCoretest
import (
"testing"
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-scenario-go/worldmock"
contextmock "github.com/multiversx/mx-chain-vm-go/mock/context"
"github.com/multiversx/mx-chain-vm-go/testcommon"
"github.com/multiversx/mx-chain-vm-go/vmhost"
)
func TestForbiddenOps_BulkAndSIMD(t *testing.T) {
wasmModules := []string{"data-drop", "memory-init", "simd"}
for _, moduleName := range wasmModules {
testCase := testcommon.BuildInstanceCallTest(t).
WithContracts(
testcommon.CreateInstanceContract(testcommon.ParentAddress).
WithCode(testcommon.GetTestSCCodeModule("forbidden-opcodes/"+moduleName, moduleName, "../../"))).
WithInput(testcommon.CreateTestContractCallInputBuilder().
WithGasProvided(100000).
WithFunction("main").
Build())
assertResults := func(_ vmhost.VMHost, _ *contextmock.BlockchainHookStub, verify *testcommon.VMOutputVerifier) {
verify.ContractInvalid()
}
testCase.AndAssertResults(assertResults)
}
}
func TestForbiddenOps_FloatingPoints(t *testing.T) {
testcommon.BuildInstanceCreatorTest(t).
WithInput(testcommon.CreateTestContractCreateInputBuilder().
WithGasProvided(1000).
WithCallValue(88).
WithArguments([]byte{2}).
WithContractCode(testcommon.GetTestSCCode("num-with-fp", "../../")).
Build()).
WithAddress(newAddress).
AndAssertResults(func(_ *contextmock.BlockchainHookStub, verify *testcommon.VMOutputVerifier) {
verify.ContractInvalid()
})
}
func TestBarnardOpcodesActivation(t *testing.T) {
testcommon.BuildInstanceCreatorTest(t).
WithInput(testcommon.CreateTestContractCreateInputBuilder().
WithGasProvided(100000000).
WithContractCode(testcommon.GetTestSCCode("new-blockchain-hooks", "../../")).
Build()).
WithEnableEpochsHandler(&worldmock.EnableEpochsHandlerStub{
IsFlagEnabledCalled: func(flag core.EnableEpochFlag) bool {
return flag != vmhost.BarnardOpcodesFlag
},
}).
AndAssertResults(func(stubBlockchainHook *contextmock.BlockchainHookStub, verify *testcommon.VMOutputVerifier) {
verify.
ContractInvalid()
})
}