github.com/aeternity/aepp-sdk-go@v1.0.3-0.20190606142815-1c0ffdc21fd9/cmd/account_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/spf13/cobra"
     9  )
    10  
    11  func TestAccountCreate(t *testing.T) {
    12  	password = "password"
    13  	emptyCmd := cobra.Command{}
    14  
    15  	dir, err := ioutil.TempDir("", "aecli")
    16  	if err != nil {
    17  		t.Error(err)
    18  	}
    19  	defer os.RemoveAll(dir)
    20  	os.Chdir(dir)
    21  
    22  	err = createFunc(&emptyCmd, []string{"test.json"})
    23  	if err != nil {
    24  		t.Error(err)
    25  	}
    26  }
    27  
    28  func TestAccountAddress(t *testing.T) {
    29  	password = "password"
    30  	emptyCmd := cobra.Command{}
    31  
    32  	dir, err := ioutil.TempDir("", "aecli")
    33  	if err != nil {
    34  		t.Error(err)
    35  	}
    36  	defer os.RemoveAll(dir)
    37  	os.Chdir(dir)
    38  
    39  	err = createFunc(&emptyCmd, []string{"test.json"})
    40  	if err != nil {
    41  		t.Error(err)
    42  	}
    43  
    44  	err = addressFunc(&emptyCmd, []string{"test.json"})
    45  	if err != nil {
    46  		t.Error(err)
    47  	}
    48  }
    49  
    50  func TestAccountSave(t *testing.T) {
    51  	password = "password"
    52  	emptyCmd := cobra.Command{}
    53  	privateKey := "025528252ec5db7d77cd57e14ae7819b9205c84abe5eef8353f88330467048f458019537ef2e809fefe1f2513cda8c8aacc74fb30f8c1f8b32d99a16b7f539b8"
    54  	dir, err := ioutil.TempDir("", "aecli")
    55  	if err != nil {
    56  		t.Error(err)
    57  	}
    58  	defer os.RemoveAll(dir)
    59  	os.Chdir(dir)
    60  
    61  	err = saveFunc(&emptyCmd, []string{"test.json", privateKey})
    62  	if err != nil {
    63  		t.Error(err)
    64  	}
    65  }
    66  
    67  func TestAccountBalanceNotFound(t *testing.T) {
    68  	setConfigTestParams()
    69  	password = "password"
    70  	emptyCmd := cobra.Command{}
    71  	dir, err := ioutil.TempDir("", "aecli")
    72  	if err != nil {
    73  		t.Error(err)
    74  	}
    75  	defer os.RemoveAll(dir)
    76  	os.Chdir(dir)
    77  
    78  	err = createFunc(&emptyCmd, []string{"test.json"})
    79  	if err != nil {
    80  		t.Error(err)
    81  	}
    82  	err = balanceFunc(&emptyCmd, []string{"test.json"})
    83  	if err.Error() != "Error: Account not found" {
    84  		t.Errorf("Expected 'Account not found' error but got %s instead", err.Error())
    85  	}
    86  }
    87  
    88  func TestAccountBalanceFound(t *testing.T) {
    89  	setConfigTestParams()
    90  	password = "password"
    91  	privateKey := "e6a91d633c77cf5771329d3354b3bcef1bc5e032c43d70b6d35af923ce1eb74dcea7ade470c9f99d9d4e400880a86f1d49bb444b62f11a9ebb64bbcfeb73fef3"
    92  	emptyCmd := cobra.Command{}
    93  	dir, err := ioutil.TempDir("", "aecli")
    94  	if err != nil {
    95  		t.Error(err)
    96  	}
    97  	defer os.RemoveAll(dir)
    98  	os.Chdir(dir)
    99  
   100  	err = saveFunc(&emptyCmd, []string{"test.json", privateKey})
   101  	if err != nil {
   102  		t.Error(err)
   103  	}
   104  	err = balanceFunc(&emptyCmd, []string{"test.json"})
   105  	if err != nil {
   106  		t.Error(err)
   107  	}
   108  }
   109  
   110  func TestAccountSign(t *testing.T) {
   111  	password = "password"
   112  	emptyCmd := cobra.Command{}
   113  	dir, err := ioutil.TempDir("", "aecli")
   114  	if err != nil {
   115  		t.Error(err)
   116  	}
   117  	defer os.RemoveAll(dir)
   118  	os.Chdir(dir)
   119  
   120  	err = createFunc(&emptyCmd, []string{"test.json"})
   121  	if err != nil {
   122  		t.Error(err)
   123  	}
   124  
   125  	err = signFunc(&emptyCmd, []string{"test.json", "tx_+E8MAaEBzqet5HDJ+Z2dTkAIgKhvHUm7REti8Rqeu2S7z+tz/vOhAR8To7CL8AFABmKmi2nYdfeAPOxMCGR/btXYTHiXvVCjCoJOIIKC5wGAkBVBMQ=="})
   126  	if err != nil {
   127  		t.Error(err)
   128  	}
   129  }