Skip to content

Commit

Permalink
create new advanceChain fct which doesn't require cast being installe…
Browse files Browse the repository at this point in the history
…d on local machine
  • Loading branch information
samlaf committed Jun 21, 2024
1 parent d8e8c84 commit bd35584
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions testutils/anvil.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testutils
import (
"context"
"fmt"
"log"
"os/exec"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -46,14 +47,10 @@ func StartAnvilContainer(anvilStateFileName string) (testcontainers.Container, e
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)
AdvanceChainByNBlocksExecInContainer(ctx, 1, anvilC)

return anvilC, nil
}
Expand Down Expand Up @@ -135,3 +132,14 @@ func AdvanceChainByNBlocks(n int, anvilEndpoint string) {
panic(err)
}
}

// AdvanceChainByNBlocks requires cast to be installed on the host machine, whereas this one doesn't.
func AdvanceChainByNBlocksExecInContainer(ctx context.Context, n int, anvilC testcontainers.Container) {
c, _, err := anvilC.Exec(ctx, []string{"cast", "rpc", "anvil_mine", fmt.Sprintf("%d", n), "--rpc-url", "http://localhost:8545"})
if err != nil {
panic(err)
}
if c != 0 {
log.Fatalf("Unable to advance anvil chain by n blocks. Expected return code 0, got %v", c)
}
}

0 comments on commit bd35584

Please sign in to comment.