github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/sdk/testutils/testmsgs.go (about)

     1  package testutils
     2  
     3  import (
     4  	"github.com/gnolang/gno/tm2/pkg/crypto"
     5  	"github.com/gnolang/gno/tm2/pkg/std"
     6  )
     7  
     8  const (
     9  	RouteMsgCounter  = "MsgCounter"
    10  	RouteMsgCounter2 = "MsgCounter2"
    11  )
    12  
    13  // ValidateBasic() fails on negative counters.
    14  // Otherwise it's up to the handlers
    15  type MsgCounter struct {
    16  	Counter       int64
    17  	FailOnHandler bool
    18  }
    19  
    20  // Implements Msg
    21  func (msg MsgCounter) Route() string                { return RouteMsgCounter }
    22  func (msg MsgCounter) Type() string                 { return "counter1" }
    23  func (msg MsgCounter) GetSignBytes() []byte         { return nil }
    24  func (msg MsgCounter) GetSigners() []crypto.Address { return nil }
    25  func (msg MsgCounter) ValidateBasic() error {
    26  	if msg.Counter >= 0 {
    27  		return nil
    28  	}
    29  	return std.ErrInvalidSequence("counter should be a non-negative integer.")
    30  }
    31  
    32  // a msg we dont know how to route
    33  type MsgNoRoute struct {
    34  	MsgCounter
    35  }
    36  
    37  func (tx MsgNoRoute) Route() string { return "noroute" }
    38  
    39  // Another counter msg. Duplicate of MsgCounter
    40  type MsgCounter2 struct {
    41  	Counter int64
    42  }
    43  
    44  // Implements Msg
    45  func (msg MsgCounter2) Route() string                { return RouteMsgCounter2 }
    46  func (msg MsgCounter2) Type() string                 { return "counter2" }
    47  func (msg MsgCounter2) GetSignBytes() []byte         { return nil }
    48  func (msg MsgCounter2) GetSigners() []crypto.Address { return nil }
    49  func (msg MsgCounter2) ValidateBasic() error {
    50  	if msg.Counter >= 0 {
    51  		return nil
    52  	}
    53  	return std.ErrInvalidSequence("counter should be a non-negative integer.")
    54  }