package gotest import ( "crypto/sha1" "encoding/hex" "fmt" "io/ioutil" "net/http" "strings" "testing" "time" ) func Test_QueryByBlockId(t *testing.T) { client := http.DefaultClient geturl := fmt.Sprintf(`http://101.37.212.15:6783/v1/transbank/blockid`) timestamp := fmt.Sprintf("%v", time.Now().Unix()) t.Logf("post url:%v", geturl) postdata := fmt.Sprintf(`{"cointype":"BCC","blockid":"51733","timestamp":"%v","signature":"%v"}`, timestamp, Signature([]byte("/v1/transbank/blockid"), 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_QueryByTransIdLoop(t *testing.T) { for i := 0; i < 100; i++ { Test_QueryByTransId(t) t.Logf("Test_QueryByTransIdLoop:%v", i) } } */ func Test_QueryByTransId(t *testing.T) { client := http.DefaultClient geturl := fmt.Sprintf(`http://101.37.212.15:6783/v1/transbank/transid`) timestamp := fmt.Sprintf("%v", time.Now().Unix()) t.Logf("post url:%v", geturl) //transcationid := "fba22732c61d177bb21e0b96ad6a10ee2a8fc19e33156907841453d38a749abd" postdata := fmt.Sprintf(`{"cointype":"BCC","transcationid":"796e2048fdf44bc7d5aa9cb25208b0f4e5ec745ae10bf974346391347127dd87","timestamp":"%v","signature":"%v"}`, timestamp, Signature([]byte("/v1/transbank/transid"), 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_QueryByAddress(t *testing.T) { client := http.DefaultClient geturl := fmt.Sprintf(`http://101.37.212.15:6783/v1/transbank/address`) timestamp := fmt.Sprintf("%v", time.Now().Unix()) t.Logf("post url:%v", geturl) postdata := fmt.Sprintf(`{"cointype":"BCC","address":"1AbHNFdKJeVL8FRZyRZoiTzG9VCmzLrtvm","timestamp":"%v","signature":"%v"}`, timestamp, Signature([]byte("/v1/transbank/address"), 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_QueryBlockHeight(t *testing.T) { client := http.DefaultClient geturl := fmt.Sprintf(`http://101.37.212.15:6783/v1/transbank/blockheight`) timestamp := fmt.Sprintf("%v", time.Now().Unix()) t.Logf("post url:%v", geturl) postdata := fmt.Sprintf(`{"cointype":"BCC","timestamp":"%v","signature":"%v"}`, timestamp, Signature([]byte("/v1/transbank/blockheight"), 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 }