123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- package gotest
- import (
- "crypto/sha1"
- "encoding/hex"
- "fmt"
- "io/ioutil"
- "net/http"
- "strings"
- "testing"
- "time"
- // "encoding/json"
- //"zcash"/*local test need*/
- )
- func Test_newaddr(t *testing.T) {
- client := http.DefaultClient
- geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/createaddr`)
- timestamp := fmt.Sprintf("%v", time.Now().Unix())
- t.Logf("post url:%v", geturl)
- //var b []byte
- postdata := fmt.Sprintf(`{"cointype":"ZEC","timestamp":"%v","signature":"%v"}`, timestamp, Signature([]byte ("/coinproxy/createaddr"), timestamp))
- request, err := http.NewRequest("POST", geturl, strings.NewReader(postdata))
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- resp, err := client.Do(request)
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- defer resp.Body.Close()
- rbs, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- t.Logf("read bytes:%v", string(rbs))
- return
- }
- func Test_Balance(t *testing.T) {
- client := http.DefaultClient
- geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/coinbalance`)
- timestamp := fmt.Sprintf("%v", time.Now().Unix())
- t.Logf("post url:%v", geturl)
- //var b []byte
- postdata := fmt.Sprintf(`{"cointype":"ZEC","timestamp":"%v","signature":"%v"}`, timestamp, Signature([]byte ("/coinproxy/coinbalance"), timestamp))
- request, err := http.NewRequest("POST", geturl, strings.NewReader(postdata))
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- resp, err := client.Do(request)
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- defer resp.Body.Close()
- rbs, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- t.Logf("read bytes:%v", string(rbs))
- return
- }
- func Test_TransInfo(t *testing.T) {
- //first get block height then test transinfo
- client := http.DefaultClient
- geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/query/transinfo`)
- timestamp := fmt.Sprintf("%v", time.Now().Unix())
- t.Logf("post url:%v", geturl)
- //var b []byte
- postdata := fmt.Sprintf(`{"cointype":"ZEC","starth":10,"endh":100,"timestamp":"%v","signature":"%v"}`, timestamp, Signature([]byte ("/coinproxy/query/transinfo"), timestamp))
- request, err := http.NewRequest("POST", geturl, strings.NewReader(postdata))
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- resp, err := client.Do(request)
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- defer resp.Body.Close()
- rbs, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- t.Logf("read bytes:%v", string(rbs))
- return
- }
- /*
- func Test_TransferAccounts(t *testing.T) {
- client := http.DefaultClient
- geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/sendcoins`)
- timestamp := fmt.Sprintf("%v", time.Now().Unix())
- t.Logf("post url:%v", geturl)
- //var b []byte
- postdata := fmt.Sprintf(`{"cointype":"ZEC","amount":"0.00005","address":"t1fY6WoALcAp8EfNTYbdyHYuaWNW4QcDz7H","timestamp":"%v","signature":"%v"}`, timestamp, Signature([]byte ("/coinproxy/sendcoins"), timestamp))
- request, err := http.NewRequest("POST", geturl, strings.NewReader(postdata))
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- resp, err := client.Do(request)
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- defer resp.Body.Close()
- rbs, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- t.Logf("read bytes:%v", string(rbs))
- return
- }
- */
- func Test_ChainHeight(t *testing.T) {
- client := http.DefaultClient
- geturl := fmt.Sprintf(`http://localhost:15741/coinproxy/blockchain/height`)
- timestamp := fmt.Sprintf("%v", time.Now().Unix())
- t.Logf("post url:%v", geturl)
- //var b []byte
- postdata := fmt.Sprintf(`{"cointype":"ZEC","timestamp":"%v","signature":"%v"}`, timestamp, Signature([]byte ("/coinproxy/blockchain/height"), timestamp))
- request, err := http.NewRequest("POST", geturl, strings.NewReader(postdata))
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- resp, err := client.Do(request)
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- defer resp.Body.Close()
- rbs, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- t.Logf("read bytes:%v", string(rbs))
- return
- }
- func Signature(body []byte, timestamp string) string {
- sha1Contain := sha1.New()
- byteSha1 := append(body, append([]byte(timestamp), []byte("coinsapi^&#@(*33")...)...)
- sha1Contain.Write(byteSha1)
- localSig := hex.EncodeToString(sha1Contain.Sum(nil))
- return localSig
- }
- //local test is ok,not support remote test by docker deploy so
- /*
- func Test_WalletGetAccountAddress(t *testing.T) {
- var zcashapi zcash.ZcashApi
- addr, err := zcashapi.WalletGetAccountAddress("")
- if err == nil {
- t.Logf("read WalletGetAccountAddress bytes:%s", addr)
- }
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- return
- }
- func Test_WalletAddrList(t *testing.T) {
- var zcashapi zcash.ZcashApi
- addr, err := zcashapi.WalletAddrList("")
- if err == nil {
- t.Logf("read WalletAddrList bytes:%s", addr)
- }
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- return
- }
- func Test_WallectInfo(t *testing.T) {
- var zcashapi zcash.ZcashApi
- addr, err := zcashapi.WallectInfo()
- if err == nil {
- t.Logf("read WallectInfo bytes:%s", addr)
- }
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- return
- }
- func Test_WalleExportWalletAddress(t *testing.T) {
- var zcashapi zcash.ZcashApi
- filedir, err := zcashapi.WalleExportWalletAddress("fuzameiwallet")
- if err == nil {
- t.Logf("read WalleExportWalletAddress bytes:%s", filedir)
- }
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- return
- }
- func Test_WallectGetNewZaddress(t *testing.T) {
- var zcashapi zcash.ZcashApi
- filedir, err := zcashapi.WallectGetNewZaddress()
- if err == nil {
- t.Logf("read WallectGetNewZaddress bytes:%s", filedir)
- zkey, err := zcashapi.WallectExportZkey(filedir)
- if err == nil {
- t.Logf("read WallectExportZkey bytes:%s", zkey)
- }
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- }
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- return
- }
- func Test_WallectListZaddresses(t *testing.T) {
- var zcashapi zcash.ZcashApi
- filedir, err := zcashapi.WallectListZaddresses()
- if err == nil {
- t.Logf("read WallectListZaddresses bytes:%s", filedir)
- }
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- return
- }
- func Test_WalleGetReceivedByAccount(t *testing.T) {
- var zcashapi zcash.ZcashApi
- filedir, err := zcashapi.WalleGetReceivedByAccount("", 1)
- if err == nil {
- t.Logf("read WalleGetReceivedByAccount bytes:%.8f", filedir)
- }
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- return
- }
- func Test_WalleGetReceivedByAddress(t *testing.T) {
- var zcashapi zcash.ZcashApi
- filedir, err := zcashapi.WalleGetReceivedByAddress("t1T8ei5znEsKhXmembrM8iQqB55GcUt6GRK", 1)
- if err == nil {
- t.Logf("read WalleGetReceivedByAddress bytes:%.8f", filedir)
- }
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- return
- }
- func Test_WalleGetbalanceByaddress(t *testing.T) {
- var zcashapi zcash.ZcashApi
- filedir, err := zcashapi.WalleGetbalanceByaddress("t1T8ei5znEsKhXmembrM8iQqB55GcUt6GRK", 1)
- if err == nil {
- t.Logf("read WalleGetbalanceByaddress bytes:%.8f", filedir)
- }
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- return
- }
- func Test_WalleGetTotalBalance(t *testing.T) {
- var zcashapi zcash.ZcashApi
- filedir, err := zcashapi.WalleGetTotalBalance(1)
- if err == nil {
- t.Logf("read WalleGetTotalBalance bytes:%s", filedir)
- }
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- return
- }
- func Test_WalletListReceivedByZaddress(t *testing.T) {
- var zcashapi zcash.ZcashApi
- filedir, err := zcashapi.WallezListReceivedByZaddress("zcdAm8ftZiDJ8G6iBfDPfeaWwh7JNcrkERFEQv1VXK7F5hwkH3K9vex9TLkxJzskqLcYKd2NPs4TeutpSk4VUPjB8wmbfUD", 1)
- if err == nil {
- t.Logf("read WallezListReceivedByZaddress bytes:%s", filedir)
- }
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- return
- }
- func Test_WalletSetTxFee(t *testing.T) {
- var zcashapi zcash.ZcashApi
- filedir, err := zcashapi.WalletSetTxFee(float64(0))
- if err == nil {
- t.Logf("read WalletSetTxFee bytes:%v", filedir)
- }
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- return
- }
- func Test_WalletZ_SendFrom(t *testing.T) {
- //sendmanyarry:= []zcash.ZcashAmountsToSend{{"t1Hy5oLGmdTLXFCqB4WMKbNacmbNuBL7q33",0.1,""}}
- //sendmanyarry := [{"address":"t1Hy5oLGmdTLXFCqB4WMKbNacmbNuBL7q33","amount":0.1,"memo":""},{"address":"t1RwAwki1n4z1i7M9oJhj9zTszTBYt6t1Lk","amount":0.2,"memo":""}]
- //sendmanyarry[0].address = "t1Hy5oLGmdTLXFCqB4WMKbNacmbNuBL7q33"
- //sendmanyarry[0].amount = 0.1
- //sendmanyarry[0].memo = ""
- //sendmanyarry[1].address = "t1RwAwki1n4z1i7M9oJhj9zTszTBYt6t1Lk"
- //sendmanyarry[1].amount = 0.3
- //sendmanyarry[1].memo = ""
- var zcashapi zcash.ZcashApi
- filedir, err := zcashapi.WalletZ_Send("t1T8ei5znEsKhXmembrM8iQqB55GcUt6GRK","zcfUAY3nq5bg2aqdj8FPf3KT5rFkTyhCLiHVvBnmVJ72ZpQwgufdqNHrBAaf8KpJzaNHf7NmtktUhBLRnqoP69sVvkjGUQg",0.000001,1,0.00000000)
- if err == nil {
- t.Logf("read WalletSetTxFee bytes:%s", filedir)
- }
- if err != nil {
- t.Errorf("err:%s", err.Error())
- return
- }
- return
- }
- */
|