aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/evm/runtime/runtime_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/vm/evm/runtime/runtime_test.go')
-rw-r--r--core/vm/evm/runtime/runtime_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/core/vm/evm/runtime/runtime_test.go b/core/vm/evm/runtime/runtime_test.go
index 762f3601d..46e4a934d 100644
--- a/core/vm/evm/runtime/runtime_test.go
+++ b/core/vm/evm/runtime/runtime_test.go
@@ -29,6 +29,7 @@ import (
"github.com/dexon-foundation/dexon/core/vm/tools"
"github.com/dexon-foundation/dexon/ethdb"
"github.com/dexon-foundation/dexon/params"
+ "github.com/stretchr/testify/assert"
)
func TestDefaults(t *testing.T) {
@@ -121,6 +122,55 @@ func TestCall(t *testing.T) {
}
}
+func TestStaticCallAndRand(t *testing.T) {
+ state, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
+ address := common.HexToAddress("0x0a")
+ address2 := common.HexToAddress("0x0b")
+ code := []byte{
+ byte(vm.EVM),
+ byte(evm.PUSH1), 0, // StaticCall retSize
+ byte(evm.PUSH1), 0, // StaticCall retOffset
+ byte(evm.PUSH1), 0, // StaticCall inputSize
+ byte(evm.PUSH1), 0, // StaticCall inputOffset
+ byte(evm.PUSH20),
+ }
+ code = append(code, address2.Bytes()...)
+ code = append(code,
+ byte(evm.PUSH1), 0xff, // StaticCall gas
+ byte(evm.STATICCALL),
+ byte(evm.RAND),
+ byte(evm.RETURN),
+ )
+ state.SetCode(address, code)
+
+ state.SetCode(address2, []byte{
+ byte(vm.EVM),
+ byte(evm.RAND),
+ byte(evm.RETURN),
+ })
+
+ cfg := &Config{
+ State: state,
+ }
+ setDefaults(cfg)
+ cfg.ChainConfig.ByzantiumBlock = new(big.Int).SetUint64(0)
+
+ pack := NewExecPack(cfg)
+ e := pack.VMList[vm.EVM]
+ sender := cfg.State.GetOrNewStateObject(cfg.Origin)
+ _, _, err := e.Call(
+ sender,
+ address,
+ nil,
+ cfg.GasLimit,
+ cfg.Value,
+ &pack,
+ )
+ assert.Equal(t, nil, err)
+ assert.Equal(t, uint64(2), pack.Context.RandCallIndex)
+ assert.Equal(t, false, pack.Context.ReadOnly)
+}
+
func BenchmarkCall(b *testing.B) {
var definition = `[{"constant":true,"inputs":[],"name":"seller","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":false,"inputs":[],"name":"abort","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"value","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[],"name":"refund","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"buyer","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":false,"inputs":[],"name":"confirmReceived","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"state","outputs":[{"name":"","type":"uint8"}],"type":"function"},{"constant":false,"inputs":[],"name":"confirmPurchase","outputs":[],"type":"function"},{"inputs":[],"type":"constructor"},{"anonymous":false,"inputs":[],"name":"Aborted","type":"event"},{"anonymous":false,"inputs":[],"name":"PurchaseConfirmed","type":"event"},{"anonymous":false,"inputs":[],"name":"ItemReceived","type":"event"},{"anonymous":false,"inputs":[],"name":"Refunded","type":"event"}]`