Skip to content

Commit ae71e08

Browse files
authored
feat: add gas limit option to raw transactor (#311)
This pull request introduces support for specifying a gas limit when generating a raw signer in the Chainlink deployments framework. The changes add a flexible options pattern to the signer generator, allowing users to set a custom gas limit if needed. Unit tests have been updated to cover this new functionality. **New feature: Gas limit support for raw signer generator** - Added a `GeneratorOptions` struct and options pattern (`GeneratorOption`, `WithGasLimit`) to `signer_generator.go`, enabling configuration of gas limit for raw signers. - Updated `TransactorFromRaw` to accept options and set the gas limit on the generated transactor if provided. [[1]](diffhunk://#diff-d969a93d4b9bf394c24013f13cd08f330806edf95bd4536a0e3b78935e38c636R27-R60) [[2]](diffhunk://#diff-d969a93d4b9bf394c24013f13cd08f330806edf95bd4536a0e3b78935e38c636R74-R76) **Testing improvements** - Enhanced unit tests in `signer_generator_test.go` to verify correct gas limit behavior, including cases with and without custom gas limits. [[1]](diffhunk://#diff-1212d4f28859805b9036ae27dd95525343ab0ec9143d856d84980583985476b2L33-R51) [[2]](diffhunk://#diff-1212d4f28859805b9036ae27dd95525343ab0ec9143d856d84980583985476b2L60-R82) **Documentation** - Added a changeset documenting the new gas limit option for the raw signer generator.
1 parent 11daf8d commit ae71e08

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

.changeset/young-colts-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"chainlink-deployments-framework": minor
3+
---
4+
5+
Add support for gas limit option on raw signer generator

chain/evm/provider/signer_generator.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,41 @@ var (
2424
_ SignerGenerator = (*transactorFromKMSSigner)(nil)
2525
)
2626

27+
// GeneratorOptions contains configuration options for the SignerGenerator.
28+
type GeneratorOptions struct {
29+
gasLimit uint64
30+
}
31+
32+
// GeneratorOption is a function that modifies GeneratorOptions.
33+
type GeneratorOption func(*GeneratorOptions)
34+
35+
func WithGasLimit(gasLimit uint64) GeneratorOption {
36+
return func(opts *GeneratorOptions) {
37+
opts.gasLimit = gasLimit
38+
}
39+
}
40+
2741
// TransactorFromRaw returns a generator which creates a transactor from a raw private key.
28-
func TransactorFromRaw(privKey string) SignerGenerator {
42+
func TransactorFromRaw(privKey string, opts ...GeneratorOption) SignerGenerator {
43+
// load default options
44+
defaultOpts := &GeneratorOptions{
45+
gasLimit: 0,
46+
}
47+
// apply provided options
48+
for _, opt := range opts {
49+
opt(defaultOpts)
50+
}
51+
2952
return &transactorFromRaw{
30-
privKey: privKey,
53+
privKey: privKey,
54+
gasLimit: defaultOpts.gasLimit,
3155
}
3256
}
3357

3458
// transactorFromRaw is a SignerGenerator that creates a transactor from a private key.
3559
type transactorFromRaw struct {
36-
privKey string
60+
privKey string
61+
gasLimit uint64
3762
}
3863

3964
// Generate parses the hex encoded private key and returns the bind transactor options.
@@ -47,6 +72,9 @@ func (g *transactorFromRaw) Generate(chainID *big.Int) (*bind.TransactOpts, erro
4772
if err != nil {
4873
return nil, err
4974
}
75+
if g.gasLimit > 0 {
76+
transactor.GasLimit = g.gasLimit
77+
}
5078

5179
return transactor, nil
5280
}

chain/evm/provider/signer_generator_test.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,25 @@ func Test_TransactorFromRaw(t *testing.T) {
3030
name string
3131
givePrivKey string
3232
giveChainID *big.Int
33-
want string
33+
giveOpts []GeneratorOption
34+
wantAddr string
35+
wantGas uint64
3436
wantErr string
3537
}{
3638
{
37-
name: "valid default account and private key",
39+
name: "valid default account and private key (no gas limit)",
3840
givePrivKey: hexPrivKey,
3941
giveChainID: testChainIDBig,
40-
want: privKeyHex,
42+
wantAddr: privKeyHex,
43+
wantGas: 0,
44+
},
45+
{
46+
name: "valid with custom gas limit",
47+
givePrivKey: hexPrivKey,
48+
giveChainID: testChainIDBig,
49+
giveOpts: []GeneratorOption{WithGasLimit(123456)},
50+
wantAddr: privKeyHex,
51+
wantGas: 123456,
4152
},
4253
{
4354
name: "invalid private key",
@@ -57,16 +68,19 @@ func Test_TransactorFromRaw(t *testing.T) {
5768
t.Run(tt.name, func(t *testing.T) {
5869
t.Parallel()
5970

60-
gen := TransactorFromRaw(tt.givePrivKey)
71+
gen := TransactorFromRaw(tt.givePrivKey, tt.giveOpts...)
6172

6273
got, err := gen.Generate(tt.giveChainID)
6374
if tt.wantErr != "" {
6475
require.Error(t, err)
6576
require.ErrorContains(t, err, tt.wantErr)
66-
} else {
67-
require.NoError(t, err)
68-
assert.Equal(t, tt.want, got.From.Hex())
77+
78+
return
6979
}
80+
81+
require.NoError(t, err)
82+
assert.Equal(t, tt.wantAddr, got.From.Hex())
83+
assert.Equal(t, tt.wantGas, got.GasLimit)
7084
})
7185
}
7286
}

0 commit comments

Comments
 (0)