Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 104 additions & 46 deletions tests/integration/testdata/base/comment_gas_measurement.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,63 @@ gnoland start

# Deploy realm without comments
gnokey maketx addpkg -pkgdir $WORK/nocomment -pkgpath gno.land/r/test/nocomment -gas-fee 100000ugnot -gas-wanted 50000000 -broadcast -chainid=tendermint_test test1
# stdout 'GAS USED:'
# stdout 'GAS USED: 328452'

# Deploy realm with comments (same logic)
gnokey maketx addpkg -pkgdir $WORK/withcomment -pkgpath gno.land/r/test/withcomment -gas-fee 100000ugnot -gas-wanted 50000000 -broadcast -chainid=tendermint_test test1
# stdout 'GAS USED:'
# stdout 'GAS USED: 343204'

# Deploy realm with heavy comments (lots of comments)
gnokey maketx addpkg -pkgdir $WORK/heavycomment -pkgpath gno.land/r/test/heavycomment -gas-fee 100000ugnot -gas-wanted 50000000 -broadcast -chainid=tendermint_test test1
# stdout 'GAS USED:'
# stdout 'GAS USED: 390698'

# Deploy caller realm
gnokey maketx addpkg -pkgdir $WORK/caller -pkgpath gno.land/r/test/caller -gas-fee 100000ugnot -gas-wanted 50000000 -broadcast -chainid=tendermint_test test1
# stdout 'GAS USED: 754645'

### Call each realm to check runtime load cost ###

# Call no comment realm
gnokey maketx call -pkgpath gno.land/r/test/nocomment -func DoAdd -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED:'
# Call no comment realm (single)
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallNoCommentOnce -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED: 308405'

# Call with comment realm (single)
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallWithCommentOnce -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED: 309863'

# Call heavy comment realm (single)
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallHeavyCommentOnce -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED: 310669'

### Call twice in same transaction (cached) ###

# Call no comment realm twice in one tx
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallNoCommentTwice -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED: 309915'

# Call with comment realm
gnokey maketx call -pkgpath gno.land/r/test/withcomment -func DoAdd -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED:'
# Call with comment realm twice in one tx
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallWithCommentTwice -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED: 311367'

# Call heavy comment realm
gnokey maketx call -pkgpath gno.land/r/test/heavycomment -func DoAdd -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED:'
# Call heavy comment realm twice in one tx
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallHeavyCommentTwice -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED: 312173'

### Second call (cached) ###
### Call 5 times in same transaction ###

# Call no comment realm again
gnokey maketx call -pkgpath gno.land/r/test/nocomment -func DoAdd -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED:'
# Call no comment realm 5x in one tx
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallNoComment5x -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED: 314367'

# Call heavy comment realm again
gnokey maketx call -pkgpath gno.land/r/test/heavycomment -func DoAdd -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED:'
# Call heavy comment realm 5x in one tx
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallHeavyComment5x -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED: 316625'

### Call with comment and heavy comment ###

# Call with comment and heavy comment realm in one tx
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallDiffentFunctionTwiceInSameTx -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED: 311488'

-- nocomment/gnomod.toml --
module = "gno.land/r/test/nocomment"
Expand All @@ -62,10 +86,6 @@ func Divide(a, b int) int {
return a / b
}

func DoAdd(cur realm) int {
return Add(1, 2)
}

-- withcomment/gnomod.toml --
module = "gno.land/r/test/withcomment"
gno = "0.9"
Expand Down Expand Up @@ -100,11 +120,6 @@ func Divide(a, b int) int {
return a / b
}

// DoAdd is an exported function that calls Add internally.
func DoAdd(cur realm) int {
return Add(1, 2)
}

-- heavycomment/gnomod.toml --
module = "gno.land/r/test/heavycomment"
gno = "0.9"
Expand Down Expand Up @@ -214,22 +229,65 @@ func Divide(a, b int) int {
return a / b
}

// DoAdd is an exported function that demonstrates internal function calls.
//
// This function serves as an entry point for external callers.
// It internally calls the Add function with predefined parameters.
//
// Parameters:
// - cur: The current realm context (required for cross-realm calls)
//
// Returns:
// - int: The result of Add(1, 2), which is 3
//
// Example:
// result := DoAdd() // result = 3
func DoAdd(cur realm) int {
// Call the internal Add function with test values
// This demonstrates how internal functions can be wrapped
// for external access
return Add(1, 2)
-- caller/gnomod.toml --
module = "gno.land/r/test/caller"
gno = "0.9"
-- caller/caller.gno --
package caller

import (
"gno.land/r/test/nocomment"
"gno.land/r/test/withcomment"
"gno.land/r/test/heavycomment"
)

// Single calls
func CallNoCommentOnce(cur realm) {
nocomment.Add(1, 2)
}

func CallWithCommentOnce(cur realm) {
withcomment.Add(1, 2)
}

func CallHeavyCommentOnce(cur realm) {
heavycomment.Add(1, 2)
}

// Double calls (same tx - test caching)
func CallNoCommentTwice(cur realm) {
nocomment.Add(1, 2)
nocomment.Add(3, 4)
}

func CallWithCommentTwice(cur realm) {
withcomment.Add(1, 2)
withcomment.Add(3, 4)
}

func CallHeavyCommentTwice(cur realm) {
heavycomment.Add(1, 2)
heavycomment.Add(3, 4)
}

// 5x calls (same tx)
func CallNoComment5x(cur realm) {
nocomment.Add(1, 2)
nocomment.Add(2, 3)
nocomment.Add(3, 4)
nocomment.Add(4, 5)
nocomment.Add(5, 6)
}

func CallHeavyComment5x(cur realm) {
heavycomment.Add(1, 2)
heavycomment.Add(2, 3)
heavycomment.Add(3, 4)
heavycomment.Add(4, 5)
heavycomment.Add(5, 6)
}

func CallDiffentFunctionTwiceInSameTx(cur realm) {
withcomment.Add(1, 2)
withcomment.Multiply(3, 4)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,46 @@ gnokey maketx addpkg -pkgdir $WORK/caller -pkgpath gno.land/r/test/caller -gas-f
### Baseline ###
# Direct call (no cross-realm)
gnokey maketx call -pkgpath gno.land/r/test/caller -func DirectCall -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED:'
# stdout 'GAS USED: 209647'

### Cross-realm depth tests ###
# Depth 1: Caller -> RealmA
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallDepth1 -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED:'
# stdout 'GAS USED: 331870'

# Depth 2: Caller -> RealmA -> RealmB
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallDepth2 -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED:'
# stdout 'GAS USED: 441563'

# Depth 3: Caller -> RealmA -> RealmB -> RealmC
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallDepth3 -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED:'
# stdout 'GAS USED: 538856'

# Depth 4: Caller -> RealmA -> RealmB -> RealmC -> RealmD
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallDepth4 -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED:'
# stdout 'GAS USED: 623797'

# Depth 5: Caller -> RealmA -> RealmB -> RealmC -> RealmD -> RealmE
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallDepth5 -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED:'
# stdout 'GAS USED: 693706'

### Second call (check caching) ###
# Depth 1 again
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallDepth1 -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED:'
### Second call in same TX (check caching) ###
# Depth 1 twice in same tx
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallDepth1Twice -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED: 333441'

# Depth 5 again
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallDepth5 -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED:'
# Depth 5 twice in same tx
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallDepth5Twice -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED: 700657'

### Multiple sequential cross-realm calls ###
# Call depth 1 x 5 times sequentially
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallDepth1x5 -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED:'
# stdout 'GAS USED: 337893'

# Call depth 2 x 5 times sequentially
gnokey maketx call -pkgpath gno.land/r/test/caller -func CallDepth2x5 -insecure-password-stdin=true -broadcast=true -chainid=tendermint_test -gas-fee 1000000ugnot -gas-wanted 1000000000 -memo "" test1
# stdout 'GAS USED:'
# stdout 'GAS USED: 452996'

-- realma/gnomod.toml --
module = "gno.land/r/test/realma"
Expand Down Expand Up @@ -226,24 +226,32 @@ func CallDepth5(cur realm) int {
return realma.CallBtoCtoDtoE(1, 2)
}

// Depth 1 twice in same tx (caching test)
func CallDepth1Twice(cur realm) {
realma.Add(1, 2)
realma.Add(3, 4)
}

// Depth 5 twice in same tx (caching test)
func CallDepth5Twice(cur realm) {
realma.CallBtoCtoDtoE(1, 2)
realma.CallBtoCtoDtoE(3, 4)
}

// Multiple depth 1 calls
func CallDepth1x5(cur realm) int {
sum := 0
sum += realma.Add(1, 2)
sum += realma.Add(2, 3)
sum += realma.Add(3, 4)
sum += realma.Add(4, 5)
sum += realma.Add(5, 6)
return sum
func CallDepth1x5(cur realm) {
realma.Add(1, 2)
realma.Add(2, 3)
realma.Add(3, 4)
realma.Add(4, 5)
realma.Add(5, 6)
}

// Multiple depth 2 calls
func CallDepth2x5(cur realm) int {
sum := 0
sum += realma.CallB(1, 2)
sum += realma.CallB(2, 3)
sum += realma.CallB(3, 4)
sum += realma.CallB(4, 5)
sum += realma.CallB(5, 6)
return sum
func CallDepth2x5(cur realm) {
realma.CallB(1, 2)
realma.CallB(2, 3)
realma.CallB(3, 4)
realma.CallB(4, 5)
realma.CallB(5, 6)
}
Loading
Loading