From 760bc608a0d1ffc1da3d5e9833139016b8cf4ceb Mon Sep 17 00:00:00 2001 From: linhpn99 Date: Tue, 9 Jul 2024 10:48:00 +0700 Subject: [PATCH] update IsSponsorTx --- tm2/pkg/std/tx.go | 17 ++++++++++------- tm2/pkg/std/tx_test.go | 10 ++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tm2/pkg/std/tx.go b/tm2/pkg/std/tx.go index e6ec154e279..e5c5df6d6af 100644 --- a/tm2/pkg/std/tx.go +++ b/tm2/pkg/std/tx.go @@ -60,22 +60,25 @@ func (tx Tx) ValidateBasic() error { return nil } -// IsSponsorTx checks if the transaction is a sponsor transaction. -// A sponsor transaction is defined as having: -// - At least one message in the transaction. -// - The first message type is "no_op". -// - More than one signer. -// - The first signer is different from all other signers. +// IsSponsorTx checks if the transaction is a valid sponsor transaction func (tx Tx) IsSponsorTx() bool { - if len(tx.Msgs) == 0 || tx.Msgs[0].Type() != "no_op" { + // At least one message in the transaction + if len(tx.Msgs) < 1 { return false } + // The first message type is "no_op" + if tx.Msgs[0].Type() != "no_op" { + return false + } + + // More than one signer signers := tx.GetSigners() if len(signers) <= 1 { return false } + // The first signer is different from all other signers for i := 1; i < len(signers); i++ { if signers[0] == signers[i] { return false diff --git a/tm2/pkg/std/tx_test.go b/tm2/pkg/std/tx_test.go index 426371103a3..e348eb93496 100644 --- a/tm2/pkg/std/tx_test.go +++ b/tm2/pkg/std/tx_test.go @@ -213,6 +213,16 @@ func TestIsSponsorTx(t *testing.T) { }, expected: true, }, + { + name: "only have no_op message", + msgs: []Msg{ + mockMsg{ + caller: addr1, + msgType: "no_op", + }, + }, + expected: false, + }, { name: "no_op message with same signers", msgs: []Msg{