Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion state-surgery/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
surgery:
go build -o ./surgery ./cmd/main.go
.PHONY: surgery

test:
go test ./...

.PHONY: surgery test
28 changes: 25 additions & 3 deletions state-surgery/hardhat/hardhat.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"path/filepath"
"strings"
"sync"

"github.com/ethereum-optimism/optimism/state-surgery/solc"
)

// `Hardhat` encapsulates all of the functionality required to interact
Expand Down Expand Up @@ -75,11 +77,11 @@ func (h *Hardhat) initDeployments() error {
if strings.Contains(path, "solcInputs") {
return nil
}

name := filepath.Join(deploymentPath, h.network, path)
if !strings.HasSuffix(name, ".json") {
if !strings.HasSuffix(path, ".json") {
return nil
}

name := filepath.Join(deploymentPath, h.network, path)
file, err := os.ReadFile(name)
if err != nil {
return err
Expand Down Expand Up @@ -247,3 +249,23 @@ func (h *Hardhat) GetBuildInfo(name string) (*BuildInfo, error) {

return buildInfos[0], nil
}

// TODO(tynes): handle fully qualified names properly
func (h *Hardhat) GetStorageLayout(name string) (*solc.StorageLayout, error) {
fqn := ParseFullyQualifiedName(name)

buildInfo, err := h.GetBuildInfo(name)
if err != nil {
return nil, err
}

for _, source := range buildInfo.Output.Contracts {
for name, contract := range source {
if name == fqn.ContractName {
return &contract.StorageLayout, nil
}
}
}

return nil, fmt.Errorf("contract not found for %s", fqn.ContractName)
}
17 changes: 17 additions & 0 deletions state-surgery/hardhat/hardhat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ func TestHardhatGetBuildInfo(t *testing.T) {
}

func TestHardhatGetDeployments(t *testing.T) {
t.Parallel()

hh, err := hardhat.New(
"goerli",
[]string{"testdata/artifacts"},
Expand All @@ -143,3 +145,18 @@ func TestHardhatGetDeployments(t *testing.T) {
require.Nil(t, err)
require.NotNil(t, deployment)
}

func TestHardhatGetStorageLayout(t *testing.T) {
t.Parallel()

hh, err := hardhat.New(
"goerli",
[]string{"testdata/artifacts"},
[]string{"testdata/deployments"},
)
require.Nil(t, err)

storageLayout, err := hh.GetStorageLayout("HelloWorld")
require.Nil(t, err)
require.NotNil(t, storageLayout)
}

Large diffs are not rendered by default.

Loading