Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gnoland): Define and implement SponsorTransaction concept #2630

Open
wants to merge 71 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
e2c19fc
define sponsor transaction
linhpn99 Jul 25, 2024
eb5effc
tmp
linhpn99 Jul 25, 2024
e7d46ea
tmp
linhpn99 Jul 25, 2024
e318092
tmp
linhpn99 Jul 25, 2024
1174794
merge master
linhpn99 Jul 25, 2024
e8b166c
Merge branch 'master' into define-sponsorTx
linhpn99 Jul 25, 2024
a28539d
fixup
linhpn99 Jul 25, 2024
f46fe68
Merge branch 'define-sponsorTx' of https://github.com/linhpn99/gno in…
linhpn99 Jul 25, 2024
c04a07d
fix up
linhpn99 Jul 25, 2024
379112a
resolve conflict
linhpn99 Jul 30, 2024
c11c586
update comment
linhpn99 Jul 30, 2024
c796d03
refactor client_txs
linhpn99 Jul 30, 2024
f689a16
update comment
linhpn99 Jul 30, 2024
aca0f19
Merge branch 'master' into define-sponsorTx
linhpn99 Jul 30, 2024
0e09264
Merge branch 'master' into define-sponsorTx
linhpn99 Jul 30, 2024
4e8cc8e
Merge branch 'master' into define-sponsorTx
linhpn99 Jul 31, 2024
053090e
Merge branch 'master' into define-sponsorTx
linhpn99 Aug 1, 2024
e7a22bf
Merge branch 'master' into define-sponsorTx
linhpn99 Aug 2, 2024
46c9c88
Merge branch 'master' into define-sponsorTx
linhpn99 Aug 10, 2024
f4bb44a
Merge branch 'master' into define-sponsorTx
linhpn99 Aug 14, 2024
f3514d9
tmp
linhpn99 Aug 23, 2024
db77bc4
resolve conflict
linhpn99 Aug 23, 2024
9f865b3
remove unused code
linhpn99 Aug 23, 2024
24be2d9
Merge branch 'master' into define-sponsorTx
linhpn99 Aug 23, 2024
54646f8
add new tests
linhpn99 Aug 23, 2024
32ba052
Merge branch 'define-sponsorTx' of https://github.com/linhpn99/gno in…
linhpn99 Aug 23, 2024
61c5874
fixup
linhpn99 Aug 23, 2024
d7b09e1
fix lint
linhpn99 Aug 23, 2024
8590510
tmp
linhpn99 Aug 26, 2024
02e0c1a
solve conflict
linhpn99 Aug 26, 2024
38a1074
update
linhpn99 Aug 28, 2024
ad47a9b
Merge branch 'master' into define-sponsorTx
linhpn99 Aug 28, 2024
0939c4f
Merge branch 'master' into define-sponsorTx
linhpn99 Sep 4, 2024
654d279
Merge branch 'gnolang:master' into master
linhpn99 Sep 4, 2024
e6d642e
tmp
linhpn99 Sep 5, 2024
b442ceb
update
linhpn99 Sep 5, 2024
70fb3a1
update
linhpn99 Sep 5, 2024
dec14a8
update txtar
linhpn99 Sep 5, 2024
a75de5d
Merge branch 'master' into define-sponsorTx
linhpn99 Sep 5, 2024
565a473
add flag to determine if fetching account is needed
linhpn99 Sep 5, 2024
0904545
Merge branch 'define-sponsorTx' of https://github.com/linhpn99/gno in…
linhpn99 Sep 5, 2024
fd1a983
Merge branch 'gnolang:master' into master
linhpn99 Sep 6, 2024
bde270f
solve conflict
linhpn99 Sep 6, 2024
ff71005
fixup
linhpn99 Sep 6, 2024
f7b3c2e
add unit tests
linhpn99 Sep 7, 2024
6f245b9
add unit tests
linhpn99 Sep 7, 2024
dee5fb1
update docs
linhpn99 Sep 7, 2024
1c412a2
Merge branch 'master' into define-sponsorTx
linhpn99 Sep 7, 2024
e53a600
update txtar
linhpn99 Sep 7, 2024
761f241
Merge branch 'define-sponsorTx' of https://github.com/linhpn99/gno in…
linhpn99 Sep 7, 2024
38cd2fc
rename
linhpn99 Sep 7, 2024
33588b2
update unit tests
linhpn99 Sep 7, 2024
f1212a1
fixup
linhpn99 Sep 7, 2024
91d203d
update
linhpn99 Sep 7, 2024
37e862d
fix cov
linhpn99 Sep 7, 2024
f522eea
fixup
linhpn99 Sep 7, 2024
38ae1f9
unit tests
linhpn99 Sep 7, 2024
c961495
fixup
linhpn99 Sep 8, 2024
5f3d3ce
wrong delete
linhpn99 Sep 8, 2024
bc49696
Merge branch 'master' into define-sponsorTx
linhpn99 Sep 11, 2024
30e5cc3
update test cases
linhpn99 Sep 12, 2024
82409ad
Merge branch 'define-sponsorTx' of https://github.com/linhpn99/gno in…
linhpn99 Sep 12, 2024
2c91792
correct comment
linhpn99 Sep 18, 2024
d9b6904
add integration test for multi call msgs
linhpn99 Sep 18, 2024
24c486f
fix lint
linhpn99 Sep 18, 2024
6e0929a
Update integration_test.go
linhpn99 Sep 18, 2024
cbc607b
Merge branch 'master' into define-sponsorTx
linhpn99 Sep 21, 2024
e712ddd
fix test case
linhpn99 Sep 21, 2024
587ae5d
add test case for multiple msgs & signers
linhpn99 Sep 21, 2024
1f0e238
fix linter
linhpn99 Sep 21, 2024
7588907
update
linhpn99 Sep 21, 2024
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
12 changes: 10 additions & 2 deletions contribs/gnodev/pkg/dev/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,17 @@ func testingCallRealm(t *testing.T, node *Node, msgs ...vm.MsgCall) (*core_types
RPCClient: node.Client(),
}

signerInfo, err := signer.Info()
require.NoError(t, err)

acc, _, err := cli.QueryAccount(signerInfo.GetAddress())
require.NoError(t, err)

txcfg := gnoclient.BaseTxCfg{
GasFee: ugnot.ValueString(1000000), // Gas fee
GasWanted: 2_000_000, // Gas wanted
GasFee: ugnot.ValueString(1000000), // Gas fee
GasWanted: 2_000_000, // Gas wanted
AccountNumber: acc.AccountNumber,
SequenceNumber: acc.Sequence,
}

// Set Caller in the msgs
Expand Down
1 change: 1 addition & 0 deletions docs/gno-tooling/cli/gnokey/state-changing-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ The `addpkg` subcommmand uses the following flags and arguments:
- `-gas-fee` - amount of GNOTs to pay per gas unit
- `-chain-id` - id of the chain that we are sending the transaction to
- `-remote` - specifies the remote node RPC listener address
- `-sponsor` - bech32 address of the sponsor who pay gas fee for the transaction

The `-pkgpath` and `-pkgdir` flags are unique to the `addpkg` subcommand, while
`-broadcast`,`-send`, `-gas-wanted`, `-gas-fee`, `-chain-id`, and `-remote` are
Expand Down
107 changes: 107 additions & 0 deletions gno.land/cmd/gnoland/testdata/sponsor_addpkg_for_existed_acc.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Test for performing a sponsor addpkg transaction for an existed on-chain account (sponsoree)

# Add new sponsor account
adduser sponsor

# Add new sponsoree account
adduser sponsoree

# start a new node
gnoland start

# Query sponsor's account before the transaction to check initial state
gnokey query auth/accounts/${USER_ADDR_sponsor}
stdout 'height: 0'
stdout 'data: {'
stdout ' "BaseAccount": {'
stdout ' "address": '
stdout ' "coins": "10000000ugnot",'
stdout ' "public_key": null,'
stdout ' "account_number": "\d+",'
stdout ' "sequence": "0"'
stdout ' }'
stdout '}'
! stderr '.+' # Ensure no errors

# Query sponsoree's account before the transaction to check initial state
gnokey query auth/accounts/${USER_ADDR_sponsoree}
stdout 'height: 0'
stdout 'data: {'
stdout ' "BaseAccount": {'
stdout ' "address": '
stdout ' "coins": "10000000ugnot",'
stdout ' "public_key": null,'
stdout ' "account_number": "\d+",'
stdout ' "sequence": "0"'
stdout ' }'
stdout '}'
! stderr '.+' # Ensure no errors

# Sponsoree creates the transaction (deploy nft realm)
gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/${USER_ADDR_sponsoree}/nft -gas-fee 1000000ugnot -gas-wanted 20000000 -chainid=tendermint_test -sponsor=${USER_ADDR_sponsor} sponsoree
cp stdout sponsor.tx

# Sponsoree signs the transaction
gnokey sign -tx-path $WORK/sponsor.tx -chainid "tendermint_test" -fetch-account-info=true sponsoree
cmpenv stdout sign.stdout.golden

# Sponsor countersigns the transaction
gnokey sign -tx-path $WORK/sponsor.tx -chainid "tendermint_test" -fetch-account-info=true sponsor
cmpenv stdout sign.stdout.golden

# Sponsor broadcasts the transaction
gnokey broadcast $WORK/sponsor.tx

# Compare output to ensure the transaction was successful
stdout OK!
stdout 'GAS WANTED: 20000000'
stdout 'GAS USED: \d+'
stdout 'HEIGHT: \d+'
stdout 'EVENTS: \[\]'
stdout 'TX HASH: '

# Query sponsor's account after the transaction to see gas deduction
gnokey query auth/accounts/${USER_ADDR_sponsor}
stdout 'height: 0'
stdout 'data: {'
stdout ' "BaseAccount": {'
stdout ' "address": '
stdout ' "coins": "9000000ugnot",' # 1000000 ugnot gas deducted from sponsor's balance
stdout ' "public_key": {'
stdout ' "@type": "/tm.PubKeySecp256k1",'
stdout ' "value": '
stdout ' },'
stdout ' "account_number": "\d+",'
stdout ' "sequence": "1"' # Sequence incremented after transaction
stdout ' }'
stdout '}'
! stderr '.+' # Ensure no errors

# Query sponsoree's account after the transaction
gnokey query auth/accounts/${USER_ADDR_sponsoree}
stdout 'height: 0'
stdout 'data: {'
stdout ' "BaseAccount": {'
stdout ' "address": '
stdout ' "coins": "10000000ugnot",' # Sponsoree's balance remains the same (sponsor paid the fees)
stdout ' "public_key": {'
stdout ' "@type": "/tm.PubKeySecp256k1",'
stdout ' "value": '
stdout ' },'
stdout ' "account_number": "\d+",'
stdout ' "sequence": "1"' # Sequence incremented after transaction
stdout ' }'
stdout '}'
! stderr '.+' # Ensure no errors


-- nft.gno --
package nft

func Mint() string {
return "Minted NFT successful"
}

-- sign.stdout.golden --

Tx successfully signed and saved to $WORK/sponsor.tx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Test for performing a sponsor transaction for an non-existed on-chain account (sponsoree)

# Add new sponsor account
adduser sponsor

# Create a sponsoree key (only the key, without creating the on-chain account)
addkey sponsoree

# start a new node
gnoland start

# Query sponsoree's account before
gnokey query auth/accounts/${USER_ADDR_sponsor}
stdout 'height: 0'
stdout 'data: {'
stdout ' "BaseAccount": {'
stdout ' "address": '
stdout ' "coins": "10000000ugnot",'
stdout ' "public_key": null,'
stdout ' "account_number": "\d+",'
stdout ' "sequence": "0"'
stdout ' }'
stdout '}'
! stderr '.+' # Ensure no errors

# Query sponsor's account before
gnokey query auth/accounts/${USER_ADDR_sponsoree}
stdout 'height: 0'
stdout 'data: null'

# Sponsoree make a call transaction
gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/${USER_ADDR_sponsoree}/nft -gas-fee 1000000ugnot -gas-wanted 20000000 -chainid=tendermint_test -sponsor=${USER_ADDR_sponsor} sponsoree
cp stdout sponsor.tx

# Sponsoree signs the transaction
gnokey sign -tx-path $WORK/sponsor.tx -chainid "tendermint_test" -fetch-account-info=true sponsoree
cmpenv stdout sign.stdout.golden

# Sponsor countersigns the transaction
gnokey sign -tx-path $WORK/sponsor.tx -chainid "tendermint_test" -fetch-account-info=true sponsor
cmpenv stdout sign.stdout.golden

# Sponsor broadcasts the transaction
gnokey broadcast $WORK/sponsor.tx

# Compare output to ensure the transaction was successful
stdout OK!
stdout 'GAS WANTED: 20000000'
stdout 'GAS USED: \d+'
stdout 'HEIGHT: \d+'
stdout 'EVENTS: \[\]'
stdout 'TX HASH: '

# Query sponsor's account after the transaction to see gas deduction
gnokey query auth/accounts/${USER_ADDR_sponsor}
stdout 'height: 0'
stdout 'data: {'
stdout ' "BaseAccount": {'
stdout ' "address": '
stdout ' "coins": "9000000ugnot",' # 1000000 ugnot gas deducted from sponsor's balance
stdout ' "public_key": {'
stdout ' "@type": "/tm.PubKeySecp256k1",'
stdout ' "value": '
stdout ' },'
stdout ' "account_number": "\d+",'
stdout ' "sequence": "1"' # Sequence incremented after transaction
stdout ' }'
stdout '}'
! stderr '.+' # Ensure no errors

# Query sponsoree's account after the transaction
gnokey query auth/accounts/${USER_ADDR_sponsoree}
stdout 'height: 0'
stdout 'data: {'
stdout ' "BaseAccount": {'
stdout ' "address": '
stdout ' "coins": "",' # Sponsoree has no coins (sponsor paid the fees)
stdout ' "public_key": {'
stdout ' "@type": "/tm.PubKeySecp256k1",'
stdout ' "value": '
stdout ' },'
stdout ' "account_number": "\d+",' # Sponsoree's new account number
stdout ' "sequence": "1"' # Sequence incremented after transaction
stdout ' }'
stdout '}'
! stderr '.+' # Ensure no errors


-- nft.gno --
package nft

func Mint() string {
return "Minted NFT successful"
}

-- sign.stdout.golden --

Tx successfully signed and saved to $WORK/sponsor.tx
111 changes: 111 additions & 0 deletions gno.land/cmd/gnoland/testdata/sponsor_call_for_existed_acc.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Test for performing a sponsor call transaction for an existed on-chain account (sponsoree)

# Load the package from $WORK directory
loadpkg gno.land/r/demo/nft $WORK

# Add new sponsor account
adduser sponsor

# Add new sponsoree account
adduser sponsoree

# start a new node
gnoland start

# Query sponsor's account before the transaction to check initial state
gnokey query auth/accounts/${USER_ADDR_sponsor}
stdout 'height: 0'
stdout 'data: {'
stdout ' "BaseAccount": {'
stdout ' "address": '
stdout ' "coins": "10000000ugnot",'
stdout ' "public_key": null,'
stdout ' "account_number": "\d+",'
stdout ' "sequence": "0"'
stdout ' }'
stdout '}'
! stderr '.+' # Ensure no errors

# Query sponsoree's account before the transaction to check initial state
gnokey query auth/accounts/${USER_ADDR_sponsoree}
stdout 'height: 0'
stdout 'data: {'
stdout ' "BaseAccount": {'
stdout ' "address": '
stdout ' "coins": "10000000ugnot",'
stdout ' "public_key": null,'
stdout ' "account_number": "\d+",'
stdout ' "sequence": "0"'
stdout ' }'
stdout '}'
! stderr '.+' # Ensure no errors


# Sponsoree creates the transaction (call to Mint in nft realm)
# Sponsor address is provided for sponsorship
gnokey maketx call -pkgpath gno.land/r/demo/nft -chainid=tendermint_test -func Mint -gas-fee 1000000ugnot -gas-wanted 2000000 -sponsor=${USER_ADDR_sponsor} sponsoree
cp stdout sponsor.tx

# Sponsoree signs the transaction
gnokey sign -tx-path $WORK/sponsor.tx -chainid "tendermint_test" -fetch-account-info=true sponsoree
cmpenv stdout sign.stdout.golden

# Sponsor countersigns the transaction
gnokey sign -tx-path $WORK/sponsor.tx -chainid "tendermint_test" -fetch-account-info=true sponsor
cmpenv stdout sign.stdout.golden

# Sponsor broadcasts the transaction
gnokey broadcast $WORK/sponsor.tx

# Compare output to ensure the transaction was successful
stdout OK!
stdout 'GAS WANTED: 2000000'
stdout 'GAS USED: \d+'
stdout 'HEIGHT: \d+'
stdout 'EVENTS: \[\]'
stdout 'TX HASH: '

# Query sponsor's account after the transaction to see gas deduction
gnokey query auth/accounts/${USER_ADDR_sponsor}
stdout 'height: 0'
stdout 'data: {'
stdout ' "BaseAccount": {'
stdout ' "address": '
stdout ' "coins": "9000000ugnot",' # 1000000 ugnot gas deducted from sponsor's balance
stdout ' "public_key": {'
stdout ' "@type": "/tm.PubKeySecp256k1",'
stdout ' "value": '
stdout ' },'
stdout ' "account_number": "\d+",'
stdout ' "sequence": "1"' # Sequence incremented after transaction
stdout ' }'
stdout '}'
! stderr '.+' # Ensure no errors

# Query sponsoree's account after the transaction
gnokey query auth/accounts/${USER_ADDR_sponsoree}
stdout 'height: 0'
stdout 'data: {'
stdout ' "BaseAccount": {'
stdout ' "address": '
stdout ' "coins": "10000000ugnot",' # Sponsoree's balance remains the same (sponsor paid the fees)
stdout ' "public_key": {'
stdout ' "@type": "/tm.PubKeySecp256k1",'
stdout ' "value": '
stdout ' },'
stdout ' "account_number": "\d+",'
stdout ' "sequence": "1"' # Sequence incremented after transaction
stdout ' }'
stdout '}'
! stderr '.+' # Ensure no errors

-- nft.gno --
package nft

func Mint() string {
return "Minted NFT successful"
}

-- sign.stdout.golden --

Tx successfully signed and saved to $WORK/sponsor.tx
Loading
Loading