code.vegaprotocol.io/vega@v0.79.0/vegatools/checktx/checktx_testdata.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package checktx
    17  
    18  import (
    19  	"encoding/base64"
    20  	"fmt"
    21  
    22  	"code.vegaprotocol.io/vega/commands"
    23  	"code.vegaprotocol.io/vega/libs/proto"
    24  	v1 "code.vegaprotocol.io/vega/protos/vega/commands/v1"
    25  )
    26  
    27  const (
    28  	TxVersion      = 3
    29  	TestAlgoName   = "testAlgo"
    30  	TestPubKeyName = "testPubKey"
    31  )
    32  
    33  var TestInputData = v1.InputData{Nonce: 123, BlockHeight: 456, Command: &v1.InputData_Transfer{Transfer: &v1.Transfer{
    34  	FromAccountType: 1,
    35  	To:              "dave",
    36  	ToAccountType:   2,
    37  	Asset:           "test asset",
    38  	Amount:          "123",
    39  	Reference:       "test ref",
    40  }}}
    41  
    42  func CreateTransaction() (*v1.Transaction, error) {
    43  	marshalledInputData, err := commands.MarshalInputData(&TestInputData)
    44  	if err != nil {
    45  		return &v1.Transaction{}, fmt.Errorf("error occurred when mashalling test input data\nerr: %w", err)
    46  	}
    47  	return commands.NewTransaction(TestPubKeyName, marshalledInputData, commands.NewSignature([]byte("sig"), TestAlgoName, TxVersion)), nil
    48  }
    49  
    50  func CreatedEncodedTransactionData() (string, error) {
    51  	transaction, err := CreateTransaction()
    52  	if err != nil {
    53  		return "", fmt.Errorf("error occurred when creating a transaction \nerr: %w", err)
    54  	}
    55  	transactionProto, err := proto.Marshal(transaction)
    56  	if err != nil {
    57  		return "", fmt.Errorf("error occurred when marshalling the transaction to a proto\nerr: %w", err)
    58  	}
    59  
    60  	encodedTransaction := base64.StdEncoding.EncodeToString(transactionProto)
    61  	return encodedTransaction, nil
    62  }