Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NIT-2619] Add TestWasmRecreateWithDelegatecall #2483

Merged
merged 9 commits into from
Jul 17, 2024
58 changes: 44 additions & 14 deletions system_tests/program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1668,20 +1668,12 @@ func formatTime(duration time.Duration) string {
return fmt.Sprintf("%.2f%s", span, units[unit])
}

func TestWasmRecreate(t *testing.T) {
builder, auth, cleanup := setupProgramTest(t, true)
func testWasmRecreate(t *testing.T, builder *NodeBuilder, storeTx *types.Transaction, loadTx *types.Transaction, want []byte) {
ctx := builder.ctx
l2info := builder.L2Info
l2client := builder.L2.Client
defer cleanup()

storage := deployWasm(t, ctx, auth, l2client, rustFile("storage"))

zero := common.Hash{}
val := common.HexToHash("0x121233445566")

// do an onchain call - store value
storeTx := l2info.PrepareTxTo("Owner", &storage, l2info.TransferGas, nil, argsForStorageWrite(zero, val))
Require(t, l2client.SendTransaction(ctx, storeTx))
_, err := EnsureTxSucceeded(ctx, l2client, storeTx)
Require(t, err)
Expand All @@ -1694,11 +1686,10 @@ func TestWasmRecreate(t *testing.T) {
Require(t, err)

// make sure reading 2nd value succeeds from 2nd node
loadTx := l2info.PrepareTxTo("Owner", &storage, l2info.TransferGas, nil, argsForStorageRead(zero))
result, err := arbutil.SendTxAsCall(ctx, nodeB.Client, loadTx, l2info.GetAddress("Owner"), nil, true)
Require(t, err)
if common.BytesToHash(result) != val {
Fatal(t, "got wrong value")
if !bytes.Equal(result, want) {
t.Fatalf("got wrong value, got %x, want %x", result, want)
}
// close nodeB
cleanupB()
Expand All @@ -1723,8 +1714,8 @@ func TestWasmRecreate(t *testing.T) {
// test nodeB - answers eth_call (requires reloading wasm)
result, err = arbutil.SendTxAsCall(ctx, nodeB.Client, loadTx, l2info.GetAddress("Owner"), nil, true)
Require(t, err)
if common.BytesToHash(result) != val {
Fatal(t, "got wrong value")
if !bytes.Equal(result, want) {
t.Fatalf("got wrong value, got %x, want %x", result, want)
}

// send new tx (requires wasm) and check nodeB sees it as well
Expand All @@ -1743,7 +1734,46 @@ func TestWasmRecreate(t *testing.T) {
Fatal(t, "not contents found before delete")
}
os.RemoveAll(wasmPath)
}

func TestWasmRecreate(t *testing.T) {
builder, auth, cleanup := setupProgramTest(t, true)
ctx := builder.ctx
l2info := builder.L2Info
l2client := builder.L2.Client
defer cleanup()

storage := deployWasm(t, ctx, auth, l2client, rustFile("storage"))

zero := common.Hash{}
val := common.HexToHash("0x121233445566")

storeTx := l2info.PrepareTxTo("Owner", &storage, l2info.TransferGas, nil, argsForStorageWrite(zero, val))
loadTx := l2info.PrepareTxTo("Owner", &storage, l2info.TransferGas, nil, argsForStorageRead(zero))

testWasmRecreate(t, builder, storeTx, loadTx, val[:])
}

func TestWasmRecreateWithDelegatecall(t *testing.T) {
builder, auth, cleanup := setupProgramTest(t, true)
ctx := builder.ctx
l2info := builder.L2Info
l2client := builder.L2.Client
defer cleanup()

storage := deployWasm(t, ctx, auth, l2client, rustFile("storage"))
multicall := deployWasm(t, ctx, auth, l2client, rustFile("multicall"))

zero := common.Hash{}
val := common.HexToHash("0x121233445566")

data := argsForMulticall(vm.DELEGATECALL, storage, big.NewInt(0), argsForStorageWrite(zero, val))
storeTx := l2info.PrepareTxTo("Owner", &multicall, l2info.TransferGas, nil, data)

data = argsForMulticall(vm.DELEGATECALL, storage, big.NewInt(0), argsForStorageRead(zero))
loadTx := l2info.PrepareTxTo("Owner", &multicall, l2info.TransferGas, nil, data)

testWasmRecreate(t, builder, storeTx, loadTx, val[:])
}

// createMapFromDb is used in verifying if wasm store rebuilding works
Expand Down
Loading