Skip to content

Commit 2f3af21

Browse files
authored
Merge pull request #2237 from CosmWasm/co/improve-gas-tests
Fix and simplify recurse gas tests
2 parents a506927 + 4bc9f34 commit 2f3af21

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

x/wasm/keeper/recurse_test.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ func initRecurseContract(t *testing.T) (contract sdk.AccAddress, ctx sdk.Context
5656

5757
func TestGasCostOnQuery(t *testing.T) {
5858
const (
59-
GasNoWork uint64 = 63_987 + 6
60-
GasNoWorkDiscounted uint64 = 5_968
61-
// Note: about 100 SDK gas (10k CosmWasm gas) for each round of sha256
62-
GasWork50 uint64 = 64_234 + 6 // this is a little shy of 50k gas - to keep an eye on the limit
63-
GasWork50Discounted uint64 = 6_207
64-
65-
GasReturnUnhashed uint64 = 89 + 10
66-
GasReturnHashed uint64 = 86 + 10
59+
GasNoWork uint64 = 63_993
60+
GasWork50 uint64 = 64_240
61+
// should be discounted exactly by the difference between normal instance cost and discounted instance cost
62+
GasNoWorkDiscounted uint64 = GasNoWork - (types.DefaultInstanceCost - types.DefaultInstanceCostDiscount)
63+
GasWork50Discounted uint64 = GasWork50 - (types.DefaultInstanceCost - types.DefaultInstanceCostDiscount)
64+
65+
GasReturnUnhashed uint64 = 74
66+
GasReturnHashed uint64 = 63
6767
)
6868

6969
cases := map[string]struct {
@@ -214,12 +214,16 @@ func TestLimitRecursiveQueryGas(t *testing.T) {
214214

215215
const (
216216
// Note: about 100 SDK gas (10k CosmWasm gas) for each round of sha256
217-
GasWork2k uint64 = 76_817 + 5 // = SetupContractCost + x // we have 6x gas used in cpu than in the instance
217+
GasWork2k uint64 = 76_822 // = SetupContractCost + x // we have 6x gas used in cpu than in the instance
218218

219-
GasWork2kDiscounted uint64 = 18_264 + 432 + 10
219+
// should be discounted exactly by the difference between normal instance cost and discounted instance cost
220+
GasWork2kDiscounted uint64 = GasWork2k - (types.DefaultInstanceCost - types.DefaultInstanceCostDiscount)
220221

221222
// This is overhead for calling into a sub-contract
222-
GasReturnHashed uint64 = 48 + 132
223+
GasReturnHashed uint64 = 64
224+
225+
// lots of additional gas for long error message
226+
GasError uint64 = 3408
223227
)
224228

225229
cases := map[string]struct {
@@ -268,8 +272,8 @@ func TestLimitRecursiveQueryGas(t *testing.T) {
268272
},
269273
expectQueriesFromContract: 10,
270274
expectOutOfGas: false,
271-
expectError: "query wasm contract failed", // Error we get from the contract instance doing the failing query, not wasmd
272-
expectedGas: GasWork2k + GasReturnHashed + 9*(GasWork2kDiscounted+GasReturnHashed) + 3279 + 13, // lots of additional gas for long error message
275+
expectError: "query wasm contract failed", // Error we get from the contract instance doing the failing query, not wasmd
276+
expectedGas: GasWork2k + GasReturnHashed + 9*(GasWork2kDiscounted+GasReturnHashed) + GasError,
273277
},
274278
}
275279

0 commit comments

Comments
 (0)