gas_test.gno
1.03 Kb · 33 lines
1package qrc
2
3import "testing"
4
5// The tests below tell what one call to Verify costs in gas. Run
6//
7// gno test -v -run TestGas ./qrc
8//
9// and, for each hash function, subtract the gas of the Setup test from the
10// gas of the Verify test, then divide by gasRuns. The figure covers the
11// virtual machine alone: a transaction also pays for its size and for what
12// it stores.
13const (
14 gasRuns = 10
15 gasHeight = MinHeight
16 gasLeaf = 37
17)
18
19var gasMessage = []byte("bind this key to my account")
20
21func gasVerify(t *testing.T, h Hash, runs int) {
22 root, proof := testProof(h, gasHeight, gasLeaf, gasMessage)
23 for i := 0; i < runs; i++ {
24 if err := Verify(h, root, gasHeight, gasLeaf, gasMessage, proof); err != nil {
25 t.Fatalf("%s: %v", h, err)
26 }
27 }
28}
29
30func TestGasSetupSHA256(t *testing.T) { gasVerify(t, SHA256, 0) }
31func TestGasVerifySHA256(t *testing.T) { gasVerify(t, SHA256, gasRuns) }
32func TestGasSetupKeccak256(t *testing.T) { gasVerify(t, Keccak256, 0) }
33func TestGasVerifyKeccak256(t *testing.T) { gasVerify(t, Keccak256, gasRuns) }