1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package script
import (
"testing"
"github.com/holiman/uint256"
"github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum-optimism/optimism/op-chain-ops/foundry"
"github.com/ethereum-optimism/optimism/op-service/testlog"
)
//go:generate ./testdata/generate.sh
func TestScript(t *testing.T) {
logger, captLog := testlog.CaptureLogger(t, log.LevelInfo)
af := foundry.OpenArtifactsDir("./testdata/test-artifacts")
scriptContext := DefaultContext
h := NewHost(logger, af, nil, scriptContext)
addr, err := h.LoadContract("ScriptExample.s.sol", "ScriptExample")
require.NoError(t, err)
require.NoError(t, h.EnableCheats())
h.SetEnvVar("EXAMPLE_BOOL", "true")
input := bytes4("run()")
returnData, _, err := h.Call(scriptContext.Sender, addr, input[:], DefaultFoundryGasLimit, uint256.NewInt(0))
require.NoError(t, err, "call failed: %x", string(returnData))
require.NotNil(t, captLog.FindLog(testlog.NewMessageFilter("sender nonce 1")))
require.NoError(t, h.cheatcodes.Precompile.DumpState("noop"))
// and a second time, to see if we can revisit the host state.
require.NoError(t, h.cheatcodes.Precompile.DumpState("noop"))
}