11package blockchain
22
33import (
4+ "os"
5+ "path/filepath"
46 "strings"
57
68 "github.com/testcontainers/testcontainers-go"
@@ -17,21 +19,51 @@ func defaultAnvilZksync(in *Input) {
1719 }
1820}
1921
22+ const dockerFile = `FROM ubuntu:latest
23+ RUN apt update
24+ RUN apt install -y curl git
25+ RUN curl -L https://raw.githubusercontent.com/matter-labs/foundry-zksync/main/install-foundry-zksync | bash`
26+
27+ // anvil-zskync has no public image builds. this method will build the image from source
28+ // creating a dockerfile in a temporary directory with the necessary commands to install
29+ // foundry-zksync.
30+ // see: https://foundry-book.zksync.io/getting-started/installation#using-foundry-with-docker
2031func newAnvilZksync (in * Input ) (* Output , error ) {
2132 defaultAnvilZksync (in )
2233 req := baseRequest (in )
2334
24- // anvil-zskync has no public image builds.
25- // see: https://foundry-book.zksync.io/getting-started/installation#using-foundry-with-docker
35+ tempDir , err := os .MkdirTemp ("." , "anvil-zksync-dockercontext-" )
36+ if err != nil {
37+ return nil , err
38+ }
39+
40+ dockerfilePath := filepath .Join (tempDir , "anvilZksync.Dockerfile" )
41+
42+ if err := os .WriteFile (dockerfilePath , []byte (dockerFile ), 0644 ); err != nil {
43+ return nil , err
44+ }
2645 req .FromDockerfile = testcontainers.FromDockerfile {
27- Context : "." ,
46+ Context : tempDir ,
2847 Dockerfile : "anvilZksync.Dockerfile" ,
2948 KeepImage : true ,
3049 }
3150
32- req .Entrypoint = []string {"/bin/sh" , "-c" , "/root/.foundry/bin/anvil-zksync --offline run" }
51+ req .Entrypoint = []string {
52+ "/bin/sh" ,
53+ "-c" ,
54+ "/root/.foundry/bin/anvil-zksync --offline --chain-id " + in .ChainID + " --port " + in .Port + " run" ,
55+ }
3356
3457 framework .L .Info ().Any ("Cmd" , strings .Join (req .Entrypoint , " " )).Msg ("Creating anvil with command" )
3558
36- return createGenericEvmContainer (in , req )
59+ output , err := createGenericEvmContainer (in , req )
60+ if err != nil {
61+ return nil , err
62+ }
63+
64+ if err := os .RemoveAll (tempDir ); err != nil {
65+ return nil , err
66+ }
67+
68+ return output , nil
3769}
0 commit comments