Skip to content

Commit 5d1b521

Browse files
Merge branch 'master' into JonathanOppenheimer/sync-pr-1394-ci-lint-fixes
Signed-off-by: Jonathan Oppenheimer <[email protected]>
2 parents f7ad0df + c65752b commit 5d1b521

File tree

65 files changed

+2311
-1894
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2311
-1894
lines changed

.avalanche-golangci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ linters:
8282
- unparam
8383
- unused
8484
- usestdlibvars
85+
- usetesting
8586
- whitespace
8687
settings:
8788
depguard:
@@ -228,6 +229,14 @@ linters:
228229
# Mark all local variables as used.
229230
# default: true
230231
local-variables-are-used: false
232+
usetesting:
233+
os-create-temp: true # Disallow `os.CreateTemp("", ...)`
234+
os-mkdir-temp: true # Disallow `os.MkdirTemp()`
235+
os-setenv: true # Disallow `os.Setenv()`
236+
os-temp-dir: true # Disallow `os.TempDir()`
237+
os-chdir: true # Disallow `os.Chdir()`
238+
context-background: true # Disallow `context.Background()`
239+
context-todo: true # Disallow `context.TODO()`
231240
exclusions:
232241
generated: lax
233242
presets:

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ jobs:
2222
cache-dependency-path: |
2323
go.sum
2424
tools/go.sum
25+
tools/legacy-golangci-lint.sum
26+
- name: Set up solc
27+
uses: ARR4N/[email protected]
28+
with:
29+
versions: '0.8.30'
2530
- name: Run all lint checks
2631
run: ./scripts/run_task.sh lint-all-ci
2732
- name: Check go.mod and go.sum are up-to-date

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,6 @@ avalanchego/
6464

6565
# Contract compilation artifacts (binary files are not committed)
6666
contracts/artifacts/
67+
68+
# solc downloads from setup-solc GitHub Action
69+
setup-solc_downloads/

Taskfile.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ tasks:
6666
- task: generate-rlp
6767
- task: check-clean-branch
6868

69+
check-generate-bindings:
70+
desc: Checks that generated Go bindings from Solidity contracts in precompile are up-to-date (requires a clean git working tree)
71+
cmds:
72+
- task: generate-bindings
73+
- task: check-clean-branch
74+
6975
check-go-mod-tidy:
7076
desc: Checks that all go.mod and go.sum files are up-to-date (requires a clean git working tree)
7177
cmds:
@@ -96,6 +102,17 @@ tasks:
96102
- cmd: grep -lr -E '^// Code generated by rlpgen\. DO NOT EDIT.\.$' . | xargs -r rm
97103
- cmd: go generate -run rlpgen ./...
98104

105+
generate-bindings:
106+
desc: Generates Go bindings from Solidity contracts in precompile
107+
cmds:
108+
- cmd: |
109+
# Find and remove generated binding files in precompile directories only
110+
find ./precompile -type f -name 'gen_*binding.go' -exec grep -l '^// Code generated - DO NOT EDIT\.$' {} \; | xargs -r rm
111+
- cmd: |
112+
# Generate bindings for precompile packages (contracts/ bindings are handled by setup-contracts separately)
113+
go generate ./precompile/...
114+
115+
99116
install-avalanchego-release:
100117
desc: Download and install AvalancheGo release binary for testing, with fallback to building from source
101118
cmd: ./scripts/install_avalanchego_release.sh # ci.yml
@@ -113,6 +130,7 @@ tasks:
113130
- check-generate-codec
114131
- check-generate-mocks
115132
- check-generate-rlp
133+
- check-generate-bindings
116134

117135
lint-all-ci:
118136
desc: Runs all lint checks one-by-one
@@ -123,6 +141,7 @@ tasks:
123141
- task: check-generate-codec
124142
- task: check-generate-mocks
125143
- task: check-generate-rlp
144+
- task: check-generate-bindings
126145

127146
lint-fix:
128147
desc: Run golangci-lint with auto-fix where possible

accounts/abi/bind/util_test.go

Lines changed: 66 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,27 @@ import (
4242
"github.com/ava-labs/subnet-evm/params"
4343
)
4444

45-
var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
46-
47-
var waitDeployedTests = map[string]struct {
48-
code string
49-
gas uint64
50-
wantAddress common.Address
51-
wantErr error
52-
}{
53-
"successful deploy": {
54-
code: `6060604052600a8060106000396000f360606040526008565b00`,
55-
gas: 3000000,
56-
wantAddress: common.HexToAddress("0x3a220f351252089d385b29beca14e27f204c296a"),
57-
},
58-
"empty code": {
59-
code: ``,
60-
gas: 300000,
61-
wantErr: bind.ErrNoCodeAfterDeploy,
62-
wantAddress: common.HexToAddress("0x3a220f351252089d385b29beca14e27f204c296a"),
63-
},
64-
}
45+
var (
46+
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
47+
waitDeployedTests = map[string]struct {
48+
code string
49+
gas uint64
50+
wantAddress common.Address
51+
wantErr error
52+
}{
53+
"successful deploy": {
54+
code: `6060604052600a8060106000396000f360606040526008565b00`,
55+
gas: 3000000,
56+
wantAddress: common.HexToAddress("0x3a220f351252089d385b29beca14e27f204c296a"),
57+
},
58+
"empty code": {
59+
code: ``,
60+
gas: 300000,
61+
wantErr: bind.ErrNoCodeAfterDeploy,
62+
wantAddress: common.HexToAddress("0x3a220f351252089d385b29beca14e27f204c296a"),
63+
},
64+
}
65+
)
6566

6667
func TestWaitDeployed(t *testing.T) {
6768
t.Parallel()
@@ -94,7 +95,7 @@ func TestWaitDeployed(t *testing.T) {
9495

9596
// Send and mine the transaction.
9697
if err := backend.Client().SendTransaction(ctx, tx); err != nil {
97-
t.Fatalf("Failed to send transaction: %s", err)
98+
t.Errorf("test %q: failed to send transaction: %v", name, err)
9899
}
99100
backend.Commit(true)
100101

@@ -113,44 +114,66 @@ func TestWaitDeployed(t *testing.T) {
113114
}
114115

115116
func TestWaitDeployedCornerCases(t *testing.T) {
116-
backend := simulated.NewBackend(
117-
types.GenesisAlloc{
118-
crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(1000000000000000000)},
119-
},
117+
var (
118+
backend = simulated.NewBackend(
119+
types.GenesisAlloc{
120+
crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(1000000000000000000)},
121+
},
122+
)
123+
head, _ = backend.Client().HeaderByNumber(t.Context(), nil) // Should be child's, good enough
124+
gasPrice = new(big.Int).Add(head.BaseFee, big.NewInt(1))
125+
signer = types.LatestSignerForChainID(big.NewInt(1337))
126+
code = common.FromHex("6060604052600a8060106000396000f360606040526008565b00")
127+
ctx, cancel = context.WithCancel(t.Context())
120128
)
121129
defer backend.Close()
122130

123-
head, _ := backend.Client().HeaderByNumber(context.Background(), nil) // Should be child's, good enough
124-
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))
125-
126-
// Create a transaction to an account.
127-
code := "6060604052600a8060106000396000f360606040526008565b00"
128-
tx := types.NewTransaction(0, common.HexToAddress("0x01"), big.NewInt(0), 3000000, gasPrice, common.FromHex(code))
129-
tx, _ = types.SignTx(tx, types.LatestSignerForChainID(big.NewInt(1337)), testKey)
130-
ctx, cancel := context.WithCancel(context.Background())
131-
defer cancel()
131+
// 1. WaitDeploy on a transaction that does not deploy a contract, verify it
132+
// returns an error.
133+
tx := types.MustSignNewTx(testKey, signer, &types.LegacyTx{
134+
Nonce: 0,
135+
To: &common.Address{0x01},
136+
Gas: 300000,
137+
GasPrice: gasPrice,
138+
Data: code,
139+
})
132140
if err := backend.Client().SendTransaction(ctx, tx); err != nil {
133-
t.Fatalf("Failed to send transaction: %s", err)
141+
t.Errorf("failed to send transaction: %q", err)
134142
}
135143
backend.Commit(true)
136144
notContractCreation := errors.New("tx is not contract creation")
137145
if _, err := bind.WaitDeployed(ctx, backend.Client(), tx); err.Error() != notContractCreation.Error() {
138146
t.Errorf("error mismatch: want %q, got %q, ", notContractCreation, err)
139147
}
140148

141-
// Create a transaction that is not mined.
142-
tx = types.NewContractCreation(1, big.NewInt(0), 3000000, gasPrice, common.FromHex(code))
143-
tx, _ = types.SignTx(tx, types.LatestSignerForChainID(big.NewInt(1337)), testKey)
144-
149+
// 2. Create a contract, but cancel the WaitDeploy before it is mined.
150+
tx = types.MustSignNewTx(testKey, signer, &types.LegacyTx{
151+
Nonce: 1,
152+
Gas: 300000,
153+
GasPrice: gasPrice,
154+
Data: code,
155+
})
156+
157+
// Wait in another thread so that we can quickly cancel it after submitting
158+
// the transaction.
159+
done := make(chan struct{})
145160
go func() {
146-
contextCanceled := errors.New("context canceled")
147-
if _, err := bind.WaitDeployed(ctx, backend.Client(), tx); err.Error() != contextCanceled.Error() {
148-
t.Errorf("error mismatch: want %q, got %q, ", contextCanceled, err)
161+
defer close(done)
162+
_, err := bind.WaitDeployed(ctx, backend.Client(), tx)
163+
if !errors.Is(err, context.Canceled) {
164+
t.Errorf("error mismatch: want %v, got %v", context.Canceled, err)
149165
}
150166
}()
151167

152168
if err := backend.Client().SendTransaction(ctx, tx); err != nil {
153-
t.Fatalf("Failed to send transaction: %s", err)
169+
t.Errorf("failed to send transaction: %q", err)
154170
}
155171
cancel()
172+
173+
// Wait for goroutine to exit or for a timeout.
174+
select {
175+
case <-done:
176+
case <-time.After(time.Second * 2):
177+
t.Fatalf("failed to cancel wait deploy")
178+
}
156179
}

contracts/contracts/ExampleDeployerList.sol

Lines changed: 0 additions & 22 deletions
This file was deleted.

contracts/contracts/compile.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
package contracts
55

66
// Step 1: Compile Solidity contracts to generate ABI and bin files
7-
//go:generate solc-v0.8.30 -o ../artifacts --overwrite --abi --bin --base-path . @openzeppelin/contracts/=../node_modules/@openzeppelin/contracts/ AllowList.sol ERC20NativeMinter.sol ExampleDeployerList.sol ExampleFeeManager.sol ExampleRewardManager.sol ExampleTxAllowList.sol ExampleWarp.sol
7+
//go:generate solc-v0.8.30 -o ../artifacts --overwrite --abi --bin --base-path . @openzeppelin/contracts/=../node_modules/@openzeppelin/contracts/ AllowList.sol ERC20NativeMinter.sol ExampleFeeManager.sol ExampleRewardManager.sol ExampleTxAllowList.sol ExampleWarp.sol
88

99
// Step 2: Generate Go bindings from the compiled artifacts
1010
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type AllowList --abi ../artifacts/AllowList.abi --bin ../artifacts/AllowList.bin --out ../bindings/gen_allowlist.go
1111
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type ERC20NativeMinter --abi ../artifacts/ERC20NativeMinter.abi --bin ../artifacts/ERC20NativeMinter.bin --out ../bindings/gen_erc20nativeminter.go
12-
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type ExampleDeployerList --abi ../artifacts/ExampleDeployerList.abi --bin ../artifacts/ExampleDeployerList.bin --out ../bindings/gen_exampledeployerlist.go
1312
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type ExampleFeeManager --abi ../artifacts/ExampleFeeManager.abi --bin ../artifacts/ExampleFeeManager.bin --out ../bindings/gen_examplefeemanager.go
1413
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type ExampleRewardManager --abi ../artifacts/ExampleRewardManager.abi --bin ../artifacts/ExampleRewardManager.bin --out ../bindings/gen_examplerewardmanager.go
1514
//go:generate go run github.com/ava-labs/libevm/cmd/abigen --pkg bindings --type ExampleTxAllowList --abi ../artifacts/ExampleTxAllowList.abi --bin ../artifacts/ExampleTxAllowList.bin --out ../bindings/gen_exampletxallowlist.go

contracts/contracts/test/ExampleDeployerListTest.sol

Lines changed: 0 additions & 122 deletions
This file was deleted.

0 commit comments

Comments
 (0)