Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

gas_test.gno

1.53 Kb · 49 lines
 1package amm
 2
 3import (
 4	"testing"
 5
 6	"gno.land/p/nt/testutils/v0"
 7	"gno.land/p/nt/uassert/v0"
 8)
 9
10// A fixed four-step profile, declared in order so `gno test -v` reports one
11// `--- GAS:` figure per operation. The same four steps exist verbatim in v1,
12// so the difference between the two runs is the cost of the share accounting
13// and nothing else. See moul/gno-contracts#135.
14
15var (
16	gasAlice = testutils.TestAddress("gas-alice")
17	gasBob   = testutils.TestAddress("gas-bob")
18)
19
20// TestGas0Fund keeps the fixture cost (minting and approving both tokens for
21// both actors) out of the four measured numbers.
22func TestGas0Fund(t *testing.T) {
23	reset()
24	fund(gasAlice, 10_000_000)
25	fund(gasBob, 10_000_000)
26}
27
28func TestGas1Seed(cur realm, t *testing.T) {
29	testing.SetRealm(testing.NewUserRealm(gasAlice))
30	uassert.Equal(t, int64(1_000_000), AddLiquidity(cross(cur), keyAAA, keyBBB, 1_000_000, 4_000_000))
31}
32
33func TestGas2Swap(cur realm, t *testing.T) {
34	testing.SetRealm(testing.NewUserRealm(gasAlice))
35	uassert.Equal(t, int64(362_644), Swap(cross(cur), keyAAA, keyBBB, 100_000, 1))
36}
37
38func TestGas3Join(cur realm, t *testing.T) {
39	testing.SetRealm(testing.NewUserRealm(gasBob))
40	uassert.Equal(t, int64(90_908), AddLiquidity(cross(cur), keyAAA, keyBBB, 100_000, 1_000_000))
41}
42
43func TestGas4Exit(cur realm, t *testing.T) {
44	testing.SetRealm(testing.NewUserRealm(gasBob))
45	held := SharesOf(keyAAA, keyBBB, gasBob)
46	uassert.Equal(t, int64(90_908), held)
47	RemoveLiquidity(cross(cur), keyAAA, keyBBB, held)
48	uassert.Equal(t, int64(0), SharesOf(keyAAA, keyBBB, gasBob))
49}