github.com/aeternity/aepp-sdk-go/v6@v6.0.0/cmd/tx_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/aeternity/aepp-sdk-go/v6/config"
     7  	"github.com/aeternity/aepp-sdk-go/v6/aeternity"
     8  	"github.com/spf13/cobra"
     9  )
    10  
    11  var alice = "ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi"
    12  var bob = "ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v"
    13  
    14  func Test_txSpendFunc(t *testing.T) {
    15  	type args struct {
    16  		ttlFunc   aeternity.GetTTLFunc
    17  		nonceFunc aeternity.GetNextNonceFunc
    18  		args      []string
    19  	}
    20  	tests := []struct {
    21  		name    string
    22  		args    args
    23  		wantErr bool
    24  	}{
    25  		{
    26  			name: "Alice sends 10 to Bob",
    27  			args: args{
    28  				ttlFunc:   func(offset uint64) (ttl uint64, err error) { return 500, nil },
    29  				nonceFunc: func(address string) (nonce uint64, err error) { return 2, nil },
    30  				args:      []string{alice, bob, "10"},
    31  			},
    32  			wantErr: false,
    33  		},
    34  	}
    35  	for _, tt := range tests {
    36  		t.Run(tt.name, func(t *testing.T) {
    37  			if err := txSpendFunc(tt.args.ttlFunc, tt.args.nonceFunc, tt.args.args); (err != nil) != tt.wantErr {
    38  				t.Errorf("txSpendFunc() error = %v, wantErr %v", err, tt.wantErr)
    39  			}
    40  		})
    41  	}
    42  }
    43  
    44  func TestTxVerify(t *testing.T) {
    45  	// unsigned tx_+FMMAaEBzqet5HDJ+Z2dTkAIgKhvHUm7REti8Rqeu2S7z+tz/vOhAR8To7CL8AFABmKmi2nYdfeAPOxMCGR/btXYTHiXvVCjCoa15iD0gACCAfQBgIHqJ/Y=
    46  	// sign with ae_mainnet
    47  	signedTx := "tx_+J0LAfhCuEBcvwtyCo3FYqmINcP6lHLH/dRDcj5rUiKDqYKhPpiQ+1SBQ66rF3gdVQ1IcANcw/IayK//YgK2dsDF1VtroQEAuFX4UwwBoQHOp63kcMn5nZ1OQAiAqG8dSbtES2LxGp67ZLvP63P+86EBHxOjsIvwAUAGYqaLadh194A87EwIZH9u1dhMeJe9UKMKhrXmIPSAAIIB9AGAx+EjLg=="
    48  	config.Node.NetworkID = "ae_mainnet"
    49  	emptyCmd := cobra.Command{}
    50  
    51  	err := txVerifyFunc(&emptyCmd, []string{alice, signedTx})
    52  	if err != nil {
    53  		t.Error(err)
    54  	}
    55  }
    56  
    57  func TestTxDumpRaw(t *testing.T) {
    58  	tx := "tx_+H4iAaEBzqet5HDJ+Z2dTkAIgKhvHUm7REti8Rqeu2S7z+tz/vMFoQJei0cGdDWb3EfrY0mtZADF0LoQ4yL6z10I/3ETJ0fpKADy8Y5hY2NvdW50X3B1YmtleaEBzqet5HDJ+Z2dTkAIgKhvHUm7REti8Rqeu2S7z+tz/vMGAQXLBNnv"
    59  	emptyCmd := cobra.Command{}
    60  
    61  	err := txDumpRawFunc(&emptyCmd, []string{tx})
    62  	if err != nil {
    63  		t.Error(err)
    64  	}
    65  }
    66  
    67  func Test_txContractCreateFunc(t *testing.T) {
    68  	type args struct {
    69  		ttlFunc   aeternity.GetTTLFunc
    70  		nonceFunc aeternity.GetNextNonceFunc
    71  		args      []string
    72  	}
    73  	tests := []struct {
    74  		name    string
    75  		args    args
    76  		wantErr bool
    77  	}{
    78  		{
    79  			name: "Deploy SimpleStorage with alice (unsigned)",
    80  			args: args{
    81  				ttlFunc:   func(offset uint64) (ttl uint64, err error) { return 500, nil },
    82  				nonceFunc: func(address string) (nonce uint64, err error) { return 2, nil },
    83  				args:      []string{alice, contractSimpleStorageBytecode, contractSimpleStorageInit42},
    84  			},
    85  			wantErr: false,
    86  		},
    87  	}
    88  	for _, tt := range tests {
    89  		t.Run(tt.name, func(t *testing.T) {
    90  			if err := txContractCreateFunc(tt.args.ttlFunc, tt.args.nonceFunc, tt.args.args); (err != nil) != tt.wantErr {
    91  				t.Errorf("txContractCreateFunc() error = %v, wantErr %v", err, tt.wantErr)
    92  			}
    93  		})
    94  	}
    95  }