Skip to content

Commit ad9deba

Browse files
committed
Resolve linter
1 parent 384b982 commit ad9deba

File tree

5 files changed

+84
-11
lines changed

5 files changed

+84
-11
lines changed

internal/distributor/mock_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import (
88
type (
99
broadcastTransactionDelegate func(*std.Tx) error
1010
getAccountDelegate func(string) (*gnoland.GnoAccount, error)
11+
estimateGasDelegate func(*std.Tx) (int64, error)
1112
)
1213

1314
type mockClient struct {
1415
broadcastTransactionFn broadcastTransactionDelegate
1516
getAccountFn getAccountDelegate
17+
estimateGasFn estimateGasDelegate
1618
}
1719

1820
func (m *mockClient) BroadcastTransaction(tx *std.Tx) error {
@@ -30,3 +32,11 @@ func (m *mockClient) GetAccount(address string) (*gnoland.GnoAccount, error) {
3032

3133
return nil, nil
3234
}
35+
36+
func (m *mockClient) EstimateGas(tx *std.Tx) (int64, error) {
37+
if m.estimateGasFn != nil {
38+
return m.estimateGasFn(tx)
39+
}
40+
41+
return 0, nil
42+
}

internal/runtime/helper.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/schollz/progressbar/v3"
1010
)
1111

12+
const gasBuffer = 10_000 // 10k gas
13+
1214
// msgFn defines the transaction message constructor
1315
type msgFn func(creator std.Account, index int) std.Msg
1416

@@ -31,7 +33,7 @@ func constructTransactions(
3133
nonceMap = make(map[uint64]uint64) // accountNumber -> nonce
3234
)
3335

34-
fmt.Printf("\n🔨 Estimating Gas 🔨\n\n")
36+
fmt.Printf("\n Estimating Gas \n")
3537

3638
// Estimate the fee for the transaction batch
3739
txFee := defaultDeployTxFee
@@ -69,12 +71,13 @@ func constructTransactions(
6971
clear(tx.Signatures)
7072

7173
// Use the estimated gas limit
72-
txFee.GasWanted = gasWanted + 10_000 // 10k gas buffer
74+
txFee.GasWanted = gasWanted + gasBuffer // 10k gas buffer
7375

7476
if err = signer.SignTx(tx, creatorKey, cfg); err != nil {
7577
return nil, fmt.Errorf("unable to sign transaction, %w", err)
7678
}
7779

80+
fmt.Printf("\nEstimated Gas for 1 run tx: %d \n", tx.Fee.GasWanted)
7881
fmt.Printf("\n🔨 Constructing Transactions 🔨\n\n")
7982

8083
bar := progressbar.Default(int64(transactions), "constructing txs")

internal/runtime/helper_test.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,31 @@ func TestHelper_ConstructTransactions(t *testing.T) {
4949
}
5050
)
5151

52-
txs, err := constructTransactions(accountKeys, accounts, transactions, "dummy", getMsgFn)
52+
txs, err := constructTransactions(
53+
accountKeys,
54+
accounts,
55+
transactions,
56+
"dummy",
57+
getMsgFn,
58+
func(_ *std.Tx) (int64, error) {
59+
return defaultDeployTxFee.GasWanted, nil
60+
},
61+
)
5362
require.NoError(t, err)
5463

5564
assert.Len(t, txs, int(transactions))
5665

5766
// Make sure the constructed transactions are valid
5867
for _, tx := range txs {
5968
// Make sure the fee is valid
60-
assert.Equal(t, defaultDeployTxFee, tx.Fee)
69+
assert.Equal(
70+
t,
71+
std.NewFee(
72+
defaultDeployTxFee.GasWanted+gasBuffer,
73+
defaultDeployTxFee.GasFee,
74+
),
75+
tx.Fee,
76+
)
6177

6278
// Make sure the message is valid
6379
if len(tx.Msgs) != 1 {

internal/runtime/realm_call.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (r *realmCall) Initialize(
7979
clear(tx.Signatures)
8080

8181
tx.Fee = std.NewFee(
82-
gasWanted+10_000, // buffer with 10k gas
82+
gasWanted+gasBuffer, // buffer with 10k gas
8383
common.DefaultGasFee,
8484
)
8585

internal/runtime/runtime_test.go

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ func verifyDeployTxCommon(t *testing.T, tx *std.Tx, expectedPrefix string) {
3131
assert.Nil(t, vmMsg.Deposit)
3232

3333
// Make sure the fee is valid
34-
assert.Equal(t, tx.Fee, defaultDeployTxFee)
34+
assert.Equal(
35+
t,
36+
std.NewFee(
37+
defaultDeployTxFee.GasWanted+gasBuffer,
38+
defaultDeployTxFee.GasFee,
39+
),
40+
tx.Fee,
41+
)
3542
}
3643

3744
func TestRuntime_CommonDeployment(t *testing.T) {
@@ -68,13 +75,28 @@ func TestRuntime_CommonDeployment(t *testing.T) {
6875
r := GetRuntime(testCase.mode)
6976

7077
// Make sure there is no initialization logic
71-
initialTxs, err := r.Initialize(accounts[0], accountKeys[0], "dummy")
78+
initialTxs, err := r.Initialize(
79+
accounts[0],
80+
accountKeys[0],
81+
"dummy",
82+
func(_ *std.Tx) (int64, error) {
83+
return defaultDeployTxFee.GasWanted, nil
84+
},
85+
)
7286

7387
assert.Nil(t, initialTxs)
7488
assert.Nil(t, err)
7589

7690
// Construct the transactions
77-
txs, err := r.ConstructTransactions(accountKeys, accounts, transactions, "dummy")
91+
txs, err := r.ConstructTransactions(
92+
accountKeys,
93+
accounts,
94+
transactions,
95+
"dummy",
96+
func(_ *std.Tx) (int64, error) {
97+
return defaultDeployTxFee.GasWanted, nil
98+
},
99+
)
78100
if err != nil {
79101
t.Fatalf("unable to construct transactions, %v", err)
80102
}
@@ -104,7 +126,14 @@ func TestRuntime_RealmCall(t *testing.T) {
104126
r := GetRuntime(RealmCall)
105127

106128
// Make sure the initialization logic is present
107-
initialTxs, err := r.Initialize(accounts[0], accountKeys[0], "dummy")
129+
initialTxs, err := r.Initialize(
130+
accounts[0],
131+
accountKeys[0],
132+
"dummy",
133+
func(_ *std.Tx) (int64, error) {
134+
return defaultDeployTxFee.GasWanted, nil
135+
},
136+
)
108137
if err != nil {
109138
t.Fatalf("unable to generate init transactions, %v", err)
110139
}
@@ -118,7 +147,15 @@ func TestRuntime_RealmCall(t *testing.T) {
118147
}
119148

120149
// Construct the transactions
121-
txs, err := r.ConstructTransactions(accountKeys[1:], accounts[1:], transactions, "dummy")
150+
txs, err := r.ConstructTransactions(
151+
accountKeys[1:],
152+
accounts[1:],
153+
transactions,
154+
"dummy",
155+
func(_ *std.Tx) (int64, error) {
156+
return defaultDeployTxFee.GasWanted, nil
157+
},
158+
)
122159
if err != nil {
123160
t.Fatalf("unable to construct transactions, %v", err)
124161
}
@@ -152,6 +189,13 @@ func TestRuntime_RealmCall(t *testing.T) {
152189
assert.Contains(t, vmMsg.Args[0], "Account")
153190

154191
// Make sure the fee is valid
155-
assert.Equal(t, tx.Fee, defaultDeployTxFee)
192+
assert.Equal(
193+
t,
194+
std.NewFee(
195+
defaultDeployTxFee.GasWanted+gasBuffer,
196+
defaultDeployTxFee.GasFee,
197+
),
198+
tx.Fee,
199+
)
156200
}
157201
}

0 commit comments

Comments
 (0)