Skip to content

Commit 90fa726

Browse files
committed
fix tests and one error message
1 parent 3192f35 commit 90fa726

11 files changed

+34
-57
lines changed

seth/.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
golangci-lint 1.64.5

seth/client.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,7 @@ import (
2828

2929
const (
3030
ErrEmptyConfigPath = "toml config path is empty, set SETH_CONFIG_PATH"
31-
ErrCreateABIStore = "failed to create ABI store"
32-
ErrReadingKeys = "failed to read keys"
33-
ErrCreateNonceManager = "failed to create nonce manager"
34-
ErrCreateTracer = "failed to create tracer"
35-
ErrReadContractMap = "failed to read deployed contract map"
36-
ErrRpcHealthCheckFailed = "RPC health check failed ¯\\_(ツ)_/¯"
3731
ErrContractDeploymentFailed = "contract deployment failed"
38-
ErrNoPksEphemeralMode = "no private keys loaded, cannot fund ephemeral addresses"
39-
// unused by Seth, but used by upstream
40-
ErrNoKeyLoaded = "failed to load private key"
41-
42-
ErrSethConfigIsNil = "seth config is nil"
43-
ErrNetworkIsNil = "no Network is set in the Seth config"
44-
ErrNonceManagerConfigIsNil = "nonce manager config is nil"
45-
ErrReadOnlyWithPrivateKeys = "read-only mode is enabled, but you tried to load private keys"
46-
ErrReadOnlyEphemeralKeys = "ephemeral mode is not supported in read-only mode"
47-
ErrReadOnlyGasBumping = "gas bumping is not supported in read-only mode"
48-
ErrReadOnlyRpcHealth = "RPC health check is not supported in read-only mode"
49-
ErrReadOnlyPendingNonce = "pending nonce protection is not supported in read-only mode"
5032

5133
ContractMapFilePattern = "deployed_contracts_%s_%s.toml"
5234
RevertedTransactionsFilePattern = "reverted_transactions_%s_%s.json"
@@ -89,7 +71,7 @@ func NewClientWithConfig(cfg *Config) (*Client, error) {
8971
initDefaultLogging()
9072

9173
if cfg == nil {
92-
return nil, fmt.Errorf("Seth configuration is nil. " +
74+
return nil, fmt.Errorf("seth configuration is nil. " +
9375
"Ensure you're calling NewClientWithConfig() with a valid config, or use NewClient() to load from SETH_CONFIG_PATH environment variable. " +
9476
"See documentation for configuration examples")
9577
}

seth/client_builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func TestConfig_NoPrivateKeys_TxOpts(t *testing.T) {
339339

340340
_ = client.NewTXOpts()
341341
require.Equal(t, 1, len(client.Errors), "expected 1 error")
342-
require.Equal(t, "no private keys were loaded, but keyNum 0 was requested", client.Errors[0].Error(), "expected error message")
342+
require.Contains(t, client.Errors[0].Error(), "no private keys loaded, but tried to use key #0.", "expected error message")
343343
}
344344

345345
func TestConfig_NoPrivateKeys_Tracing(t *testing.T) {

seth/client_contract_map_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func TestContractMapNewClientIsNotCreatedWhenCorruptedContractMapFileExists(t *t
142142
cfg.ContractMapFile = file.Name()
143143
newClient, err := seth.NewClientRaw(cfg, addresses, pks)
144144
require.Error(t, err, "succeeded in creation of new client")
145-
require.Contains(t, err.Error(), seth.ErrReadContractMap, "expected error reading invalid toml")
145+
require.Contains(t, err.Error(), "failed to load deployed contracts map from", "expected error reading invalid toml")
146146
require.Nil(t, newClient, "expected new client to be nil")
147147
}
148148

@@ -162,6 +162,6 @@ func TestContractMapNewClientIsNotCreatedWhenCorruptedContractMapFileExists_Inva
162162
cfg.ContractMapFile = file.Name()
163163
newClient, err := seth.NewClientRaw(cfg, addresses, pks)
164164
require.Error(t, err, "succeeded in creation of new client")
165-
require.Contains(t, err.Error(), seth.ErrReadContractMap, "expected error reading invalid contract address")
165+
require.Contains(t, err.Error(), "failed to load deployed contracts map from", "expected error reading invalid contract address")
166166
require.Nil(t, newClient, "expected new client to be nil")
167167
}

seth/client_decode_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestSmokeDebugReverts(t *testing.T) {
3939
name: "revert with a custom err",
4040
method: "alwaysRevertsCustomError",
4141
output: map[string]string{
42-
seth.GETH: "error type: CustomErr, error values: [12 21]",
42+
seth.GETH: "transaction reverted with custom error: error type: CustomErr, error values: [12 21]",
4343
},
4444
},
4545
}
@@ -57,7 +57,7 @@ func TestSmokeDebugReverts(t *testing.T) {
5757
expectedOutput = eo
5858
}
5959
}
60-
require.Equal(t, expectedOutput, err.Error())
60+
require.Contains(t, err.Error(), expectedOutput, "expected error message to contain the reverted error type and values")
6161
})
6262
}
6363
}

seth/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestRPCHealthCheckEnabled_Node_Unhealthy(t *testing.T) {
4040

4141
_, err = seth.NewClientWithConfig(cfg)
4242
require.Error(t, err, "expected error when connecting to unhealthy node")
43-
require.Contains(t, err.Error(), seth.ErrRpcHealthCheckFailed, "expected error message when connecting to dead node")
43+
require.Contains(t, err.Error(), "RPC health check failed: failed to send transaction to network: insufficient funds for gas * price + value:", "expected error message when connecting to dead node")
4444
}
4545

4646
func TestRPCHealthCheckDisabled_Node_Unhealthy(t *testing.T) {

seth/client_trace_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ func TestTraceContractAll(t *testing.T) {
12291229
require.NoError(t, txErr, "transaction sending should not fail")
12301230
_, decodeErr := c.Decode(revertedTx, txErr)
12311231
require.Error(t, decodeErr, "transaction should have reverted")
1232-
require.Equal(t, "error type: CustomErr, error values: [12 21]", decodeErr.Error(), "expected error message to contain the reverted error type and values")
1232+
require.Equal(t, "transaction reverted with custom error: error type: CustomErr, error values: [12 21]", decodeErr.Error(), "expected error message to contain the reverted error type and values")
12331233

12341234
okTx, txErr := TestEnv.DebugContract.AddCounter(c.NewTXOpts(), big.NewInt(1), big.NewInt(2))
12351235
require.NoError(t, txErr, "transaction should not have reverted")
@@ -1282,7 +1282,7 @@ func TestTraceContractOnlyReverted(t *testing.T) {
12821282
require.NoError(t, txErr, "transaction sending should not fail")
12831283
_, decodeErr := c.Decode(revertedTx, txErr)
12841284
require.Error(t, decodeErr, "transaction should have reverted")
1285-
require.Equal(t, "error type: CustomErr, error values: [12 21]", decodeErr.Error(), "expected error message to contain the reverted error type and values")
1285+
require.Equal(t, "transaction reverted with custom error: error type: CustomErr, error values: [12 21]", decodeErr.Error(), "expected error message to contain the reverted error type and values")
12861286

12871287
okTx, txErr := TestEnv.DebugContract.AddCounter(c.NewTXOpts(), big.NewInt(1), big.NewInt(2))
12881288
require.NoError(t, txErr, "transaction should not have reverted")
@@ -1320,7 +1320,7 @@ func TestTraceContractNone(t *testing.T) {
13201320
require.NoError(t, txErr, "transaction sending should not fail")
13211321
_, decodeErr := c.Decode(revertedTx, txErr)
13221322
require.Error(t, decodeErr, "transaction should have reverted")
1323-
require.Equal(t, "error type: CustomErr, error values: [12 21]", decodeErr.Error(), "expected error message to contain the reverted error type and values")
1323+
require.Equal(t, "transaction reverted with custom error: error type: CustomErr, error values: [12 21]", decodeErr.Error(), "expected error message to contain the reverted error type and values")
13241324

13251325
okTx, txErr := TestEnv.DebugContract.AddCounter(c.NewTXOpts(), big.NewInt(1), big.NewInt(2))
13261326
require.NoError(t, txErr, "transaction should not have reverted")
@@ -1341,7 +1341,7 @@ func TestTraceContractRevertedErrNoValues(t *testing.T) {
13411341
require.NoError(t, txErr, "transaction should have reverted")
13421342
_, decodeErr := c.Decode(tx, txErr)
13431343
require.Error(t, decodeErr, "transaction should have reverted")
1344-
require.Equal(t, "error type: CustomErrNoValues, error values: []", decodeErr.Error(), "expected error message to contain the reverted error type and values")
1344+
require.Equal(t, "transaction reverted with custom error: error type: CustomErrNoValues, error values: []", decodeErr.Error(), "expected error message to contain the reverted error type and values")
13451345
require.Equal(t, 1, len(c.Tracer.GetAllDecodedCalls()), "expected 1 decoded transacton")
13461346

13471347
expectedCall := &seth.DecodedCall{
@@ -1373,7 +1373,7 @@ func TestTraceCallRevertFunctionInTheContract(t *testing.T) {
13731373
require.NoError(t, txErr, "transaction should have reverted")
13741374
_, decodeErr := c.Decode(tx, txErr)
13751375
require.Error(t, decodeErr, "transaction should have reverted")
1376-
require.Equal(t, "error type: CustomErr, error values: [12 21]", decodeErr.Error(), "expected error message to contain the reverted error type and values")
1376+
require.Equal(t, "transaction reverted with custom error: error type: CustomErr, error values: [12 21]", decodeErr.Error(), "expected error message to contain the reverted error type and values")
13771377
require.Equal(t, 1, len(c.Tracer.GetAllDecodedCalls()), "expected 1 decoded transacton")
13781378

13791379
expectedCall := &seth.DecodedCall{
@@ -1407,7 +1407,7 @@ func TestTraceCallRevertFunctionInSubContract(t *testing.T) {
14071407
require.NoError(t, txErr, "transaction should have reverted")
14081408
_, decodeErr := c.Decode(tx, txErr)
14091409
require.Error(t, decodeErr, "transaction should have reverted")
1410-
require.Equal(t, "error type: CustomErr, error values: [1001 2]", decodeErr.Error(), "expected error message to contain the reverted error type and values")
1410+
require.Equal(t, "transaction reverted with custom error: error type: CustomErr, error values: [1001 2]", decodeErr.Error(), "expected error message to contain the reverted error type and values")
14111411
require.Equal(t, 1, len(c.Tracer.GetAllDecodedCalls()), "expected 1 decoded transaction")
14121412

14131413
expectedCall := &seth.DecodedCall{
@@ -1446,7 +1446,7 @@ func TestTraceCallRevertInCallback(t *testing.T) {
14461446
require.NoError(t, txErr, "transaction should have reverted")
14471447
_, decodeErr := c.Decode(tx, txErr)
14481448
require.Error(t, decodeErr, "transaction should have reverted")
1449-
require.Equal(t, "error type: CustomErr, error values: [99 101]", decodeErr.Error(), "expected error message to contain the reverted error type and values")
1449+
require.Equal(t, "transaction reverted with custom error: error type: CustomErr, error values: [99 101]", decodeErr.Error(), "expected error message to contain the reverted error type and values")
14501450
}
14511451

14521452
func TestTraceOldPragmaNoRevertReason(t *testing.T) {
@@ -1493,7 +1493,7 @@ func TestTraceeRevertReasonNonRootSender(t *testing.T) {
14931493
require.NoError(t, txErr, "transaction should have reverted")
14941494
_, decodeErr := c.Decode(tx, txErr)
14951495
require.Error(t, decodeErr, "transaction should have reverted")
1496-
require.Equal(t, "error type: CustomErr, error values: [1001 2]", decodeErr.Error(), "expected error message to contain the reverted error type and values")
1496+
require.Equal(t, "transaction reverted with custom error: error type: CustomErr, error values: [1001 2]", decodeErr.Error(), "expected error message to contain the reverted error type and values")
14971497
require.Equal(t, 1, len(c.Tracer.GetAllDecodedCalls()), "expected 1 decoded transaction")
14981498

14991499
expectedCall := &seth.DecodedCall{

seth/config_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,19 @@ func TestConfig_ReadOnly_WithPk(t *testing.T) {
131131

132132
_, err := seth.NewClientRaw(&cfg, addrs, nil)
133133
require.Error(t, err, "succeeded in creating client")
134-
require.Equal(t, seth.ErrReadOnlyWithPrivateKeys, err.Error(), "expected different error message")
134+
require.Contains(t, err.Error(), "configuration conflict: read-only mode is enabled, but private keys were provided.", "expected different error message")
135135

136136
privateKey, err := crypto.HexToECDSA("ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
137137
require.NoError(t, err, "failed to parse private key")
138138

139139
pks := []*ecdsa.PrivateKey{privateKey}
140140
_, err = seth.NewClientRaw(&cfg, nil, pks)
141141
require.Error(t, err, "succeeded in creating client")
142-
require.Equal(t, seth.ErrReadOnlyWithPrivateKeys, err.Error(), "expected different error message")
142+
require.Contains(t, err.Error(), "configuration conflict: read-only mode is enabled, but private keys were provided.", "expected different error message")
143143

144144
_, err = seth.NewClientRaw(&cfg, addrs, pks)
145145
require.Error(t, err, "succeeded in creating client")
146-
require.Equal(t, seth.ErrReadOnlyWithPrivateKeys, err.Error(), "expected different error message")
146+
require.Contains(t, err.Error(), "configuration conflict: read-only mode is enabled, but private keys were provided.", "expected different error message")
147147
}
148148

149149
func TestConfig_ReadOnly_GasBumping(t *testing.T) {
@@ -161,7 +161,7 @@ func TestConfig_ReadOnly_GasBumping(t *testing.T) {
161161

162162
_, err := seth.NewClientRaw(&cfg, nil, nil)
163163
require.Error(t, err, "succeeded in creating client")
164-
require.Equal(t, seth.ErrReadOnlyGasBumping, err.Error(), "expected different error message")
164+
require.Contains(t, err.Error(), "gas bumping is not supported in read-only mode because it requires sending replacement transactions.", "expected different error message")
165165
}
166166

167167
func TestConfig_ReadOnly_RpcHealth(t *testing.T) {
@@ -177,7 +177,7 @@ func TestConfig_ReadOnly_RpcHealth(t *testing.T) {
177177

178178
_, err := seth.NewClientRaw(&cfg, nil, nil)
179179
require.Error(t, err, "succeeded in creating client")
180-
require.Equal(t, seth.ErrReadOnlyRpcHealth, err.Error(), "expected different error message")
180+
require.Contains(t, err.Error(), "RPC health check is not supported in read-only mode", "expected different error message")
181181
}
182182

183183
func TestConfig_ReadOnly_PendingNonce(t *testing.T) {
@@ -193,7 +193,7 @@ func TestConfig_ReadOnly_PendingNonce(t *testing.T) {
193193

194194
_, err := seth.NewClientRaw(&cfg, nil, nil)
195195
require.Error(t, err, "succeeded in creating client")
196-
require.Equal(t, seth.ErrReadOnlyPendingNonce, err.Error(), "expected different error message")
196+
require.Contains(t, err.Error(), "pending nonce protection is not supported in read-only mode because it requires transaction monitoring.", "expected different error message")
197197
}
198198

199199
func TestConfig_ReadOnly_EphemeralKeys(t *testing.T) {
@@ -210,5 +210,5 @@ func TestConfig_ReadOnly_EphemeralKeys(t *testing.T) {
210210

211211
_, err := seth.NewClientRaw(&cfg, nil, nil)
212212
require.Error(t, err, "succeeded in creating client")
213-
require.Equal(t, seth.ErrNoPksEphemeralMode, err.Error(), "expected different error message")
213+
require.Contains(t, err.Error(), "ephemeral mode requires exactly one root private key to fund ephemeral addresses, but no keys were loaded.", "expected different error message")
214214
}

seth/contract_store_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,18 @@ func TestSmokeContractABIStore(t *testing.T) {
6363
{
6464
name: "empty ABI dir",
6565
abiPath: "./contracts/emptyContractDir",
66-
err: "no ABI files found in './contracts/emptyContractDir'. Fix the path or comment out 'abi_dir' setting",
66+
err: "no ABI files (*.abi) found in directory './contracts/emptyContractDir'.",
6767
},
6868
{
6969
name: "empty gethwrappers dir",
7070
gethWrappersPaths: []string{"./contracts/emptyContractDir"},
71-
err: "failed to load geth wrappers from [./contracts/emptyContractDir]: no geth wrappers found in '[./contracts/emptyContractDir]'. Fix the path or comment out 'geth_wrappers_dirs' setting",
71+
err: "failed to load geth wrappers from [./contracts/emptyContractDir]: no geth wrapper files found in directories: [./contracts/emptyContractDir]",
7272
},
7373
{
7474
name: "empty ABI and gethwrappers dir",
7575
abiPath: "./contracts/emptyContractDir",
7676
gethWrappersPaths: []string{"./contracts/emptyContractDir"},
77-
err: "no ABI files found in './contracts/emptyContractDir'. Fix the path or comment out 'abi_dir' setting",
77+
err: "no ABI files (*.abi) found in directory './contracts/emptyContractDir'.",
7878
},
7979
{
8080
name: "no MetaData in one of gethwrappers",
@@ -84,7 +84,7 @@ func TestSmokeContractABIStore(t *testing.T) {
8484
{
8585
name: "empty MetaData in one of gethwrappers",
8686
gethWrappersPaths: []string{"./contracts/emptyMetaDataContractDir"},
87-
err: "failed to load geth wrappers from [./contracts/emptyMetaDataContractDir]: failed to parse ABI content: EOF",
87+
err: "failed to load geth wrappers from [./contracts/emptyMetaDataContractDir]: failed to parse ABI content from 'contracts/emptyMetaDataContractDir/NetworkDebugContract_Broken.go': EOF",
8888
},
8989
{
9090
name: "gethwrappers dir mixes regular go files and gethwrappers",
@@ -94,12 +94,12 @@ func TestSmokeContractABIStore(t *testing.T) {
9494
{
9595
name: "invalid ABI inside ABI dir",
9696
abiPath: "./contracts/invalidContractDir",
97-
err: "failed to parse ABI file: invalid character ':' after array element",
97+
err: "failed to parse ABI file 'NetworkDebugContract.abi': invalid character ':' after array element",
9898
},
9999
{
100100
name: "invalid ABI in gethwrappers inside dir",
101101
gethWrappersPaths: []string{"./contracts/invalidContractDir"},
102-
err: "failed to load geth wrappers from [./contracts/invalidContractDir]: failed to parse ABI content: invalid character 'i' looking for beginning of value",
102+
err: "failed to load geth wrappers from [./contracts/invalidContractDir]: failed to parse ABI content from 'contracts/invalidContractDir/NetworkDebugContract_Broken.go': invalid character 'i' looking for beginning of value",
103103
},
104104
}
105105

@@ -114,7 +114,7 @@ func TestSmokeContractABIStore(t *testing.T) {
114114
require.Equal(t, make(map[string][]uint8), cs.BINs)
115115
err = errors.New("")
116116
}
117-
require.Equal(t, tc.err, err.Error())
117+
require.Contains(t, err.Error(), tc.err, "error should match")
118118
})
119119
}
120120
}
@@ -152,7 +152,7 @@ func TestSmokeContractBINStore(t *testing.T) {
152152
name: "empty BIN dir",
153153
abiPath: "./contracts/abi",
154154
binPath: "./contracts/emptyContractDir",
155-
err: "no BIN files found in './contracts/emptyContractDir'. Fix the path or comment out 'bin_dir' setting",
155+
err: "no BIN files (*.bin) found in directory './contracts/emptyContractDir'.",
156156
},
157157
}
158158

@@ -171,7 +171,7 @@ func TestSmokeContractBINStore(t *testing.T) {
171171
} else {
172172
require.Nil(t, cs, "ContractStore should be nil")
173173
}
174-
require.Equal(t, tc.err, err.Error(), "error should match")
174+
require.Contains(t, err.Error(), tc.err, "error should match")
175175
})
176176
}
177177
}

seth/decode.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -617,13 +617,7 @@ func (m *Client) callAndGetRevertReason(tx *types.Transaction, rc *types.Receipt
617617
return err
618618
}
619619
if decodedABIErrString != "" {
620-
return fmt.Errorf("failed to decode ABI from contract code: %s\n"+
621-
"This happens when:\n"+
622-
" 1. Contract bytecode doesn't contain valid ABI metadata\n"+
623-
" 2. Contract wasn't compiled with metadata (--metadata-hash none)\n"+
624-
" 3. Contract code at the address is not a valid contract\n"+
625-
"For third-party contracts, manually load the ABI instead of relying on auto-detection",
626-
decodedABIErrString)
620+
return fmt.Errorf("transaction reverted with custom error: %s", decodedABIErrString)
627621
}
628622

629623
if plainStringErr != nil {

0 commit comments

Comments
 (0)