Skip to content

Commit

Permalink
Adds Anvil Set Storage (#1220)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalverra authored Oct 9, 2024
1 parent c31feba commit 3e5eb4d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/client/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,25 @@ func (m *RPCClient) AnvilDropTransaction(params []interface{}) error {
return nil
}

// AnvilSetStorageAt sets storage at address
// API Reference https://book.getfoundry.sh/reference/anvil/
func (m *RPCClient) AnvilSetStorageAt(params []interface{}) error {
rInt, err := rand.Int()
if err != nil {
return err
}
payload := map[string]interface{}{
"jsonrpc": "2.0",
"method": "anvil_setStorageAt",
"params": params,
"id": rInt,
}
if _, err := m.client.R().SetBody(payload).Post(m.URL); err != nil {
return errors.Wrap(err, "anvil_setStorageAt")
}
return nil
}

type CurrentBlockResponse struct {
Result string `json:"result"`
}
Expand Down
23 changes: 23 additions & 0 deletions lib/client/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"context"
"crypto/ecdsa"
"encoding/hex"
"math/big"
"testing"
"time"
Expand Down Expand Up @@ -130,6 +131,28 @@ func TestRPCAPI(t *testing.T) {
t.Logf("status: %v", status)
})

t.Run("(anvil) test set storage at address", func(t *testing.T) {
ac, err := StartAnvil([]string{"--balance", "1", "--block-time", "5"})
require.NoError(t, err)
client, err := ethclient.Dial(ac.URL)
require.NoError(t, err)

randomAddress := common.HexToAddress("0x0d2026b3EE6eC71FC6746ADb6311F6d3Ba1C000B")
storeValue := "0x0000000000000000000000000000000000000000000000000000000000000001"

anvilClient := NewRPCClient(ac.URL, nil)
err = anvilClient.AnvilSetStorageAt([]interface{}{randomAddress.Hex(), "0x0", storeValue})
require.NoError(t, err, "unable to set storage at address")

value, err := client.StorageAt(context.Background(), randomAddress, common.HexToHash("0x0"), nil)
require.NoError(t, err)
decodedStoreValue, err := hex.DecodeString(storeValue[2:])
require.NoError(t, err, "unable to decode store value")
require.Equal(t, decodedStoreValue, value)

t.Logf("value: %v", value)
})

t.Run("(anvil) test we can shrink the block and control transaction inclusion", func(t *testing.T) {
ac, err := StartAnvil([]string{"--balance", "1", "--block-time", "1"})
require.NoError(t, err)
Expand Down
2 changes: 2 additions & 0 deletions lib/k8s/e2e/common/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ func TestConnectWithoutManifest(t *testing.T) {
existingEnv = environment.New(existingEnvConfig)
l.Info().Str("Namespace", existingEnvConfig.Namespace).Msg("Existing Env Namespace")
// deploy environment to use as an existing one for the test
require.NotNil(t, existingEnv, "existingEnv is nil")
require.NotNil(t, existingEnv.Cfg, "existingEnv.Cfg is nil %v", existingEnv)
existingEnv.Cfg.JobImage = ""
existingEnv.AddHelm(ethereum.New(nil)).
AddHelm(chainlink.New(0, map[string]any{
Expand Down

0 comments on commit 3e5eb4d

Please sign in to comment.