MCPcopy Create free account
hub / github.com/CPChain/chain / TestCall

Function TestCall

core/vm/runtime/runtime_test.go:96–117  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

94}
95
96func TestCall(t *testing.T) {
97 state, _ := state.New(common.Hash{}, state.NewDatabase(database.NewMemDatabase()))
98 address := common.HexToAddress("0x0a")
99 state.SetCode(address, []byte{
100 byte(vm.PUSH1), 10,
101 byte(vm.PUSH1), 0,
102 byte(vm.MSTORE),
103 byte(vm.PUSH1), 32,
104 byte(vm.PUSH1), 0,
105 byte(vm.RETURN),
106 })
107
108 ret, _, err := Call(address, nil, &Config{State: state})
109 if err != nil {
110 t.Fatal("didn't expect error", err)
111 }
112
113 num := new(big.Int).SetBytes(ret)
114 if num.Cmp(big.NewInt(10)) != 0 {
115 t.Error("Expected 10, got", num)
116 }
117}
118
119func BenchmarkCall(b *testing.B) {
120 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"}]`

Callers

nothing calls this directly

Calls 6

CallFunction · 0.85
SetBytesMethod · 0.80
CmpMethod · 0.80
SetCodeMethod · 0.65
FatalMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected