Skip to content

Commit

Permalink
update startAnvil function to advance chain by 1 block to fix current…
Browse files Browse the repository at this point in the history
… bug
  • Loading branch information
samlaf committed Jun 20, 2024
1 parent e9f7df6 commit c2ac4d6
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion testutils/anvil.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testutils
import (
"context"
"fmt"
"os/exec"
"path/filepath"
"runtime"

Expand Down Expand Up @@ -37,10 +38,24 @@ func StartAnvilContainer(anvilStateFileName string) (testcontainers.Container, e
},
}
}
return testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
anvilC, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
})
if err != nil {
return nil, err
}

anvilHttpEndpoint, err := anvilC.Endpoint(context.Background(), "http")
if err != nil {
return nil, err
}
// Still need to advance the chain by at least 1 block b/c some tests need to query the latest block,
// and the blocks dumped/loaded by anvil don't contain full transactions, which leads to panics in tests.
// See https://github.com/foundry-rs/foundry/issues/8213, which will hopefully get fixed soon.
AdvanceChainByNBlocks(1, anvilHttpEndpoint)

return anvilC, nil
}

type ContractAddresses struct {
Expand Down Expand Up @@ -107,3 +122,16 @@ func GetContractAddressesFromContractRegistry(ethHttpUrl string) (mockAvsContrac
}
return mockAvsContracts
}

func AdvanceChainByNBlocks(n int, anvilEndpoint string) {
cmd := exec.Command("bash", "-c",
fmt.Sprintf(
// see https://book.getfoundry.sh/reference/anvil/#custom-methods
`cast rpc anvil_mine %d --rpc-url %s`,
n, anvilEndpoint),
)
err := cmd.Run()
if err != nil {
panic(err)
}
}

0 comments on commit c2ac4d6

Please sign in to comment.