github.com/annchain/OG@v0.0.9/tests/sendArchives/send_test.go (about)

     1  // Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  package sendArchives
    15  
    16  import (
    17  	"encoding/json"
    18  	"fmt"
    19  	"github.com/annchain/OG/arefactor/common/httplib"
    20  	"testing"
    21  	"time"
    22  )
    23  
    24  type TxReq struct {
    25  	Data string `json:"data"`
    26  }
    27  
    28  func TestArchives(t *testing.T) {
    29  	Host := "http://192.168.45.149:11300"
    30  	var i uint
    31  	for {
    32  		select {
    33  		case <-time.After(time.Millisecond * 200):
    34  			i++
    35  			var data []byte
    36  			if i > 255 {
    37  				data = append(data, byte(i), byte(i), byte(i))
    38  			} else {
    39  				j := i / 255
    40  				m := i % 255
    41  				c := m / 255
    42  				data = append(data, byte(c), byte(j), byte(m))
    43  			}
    44  			req := httplib.Post(Host + "/new_archive")
    45  
    46  			txReq := TxReq{
    47  				Data: string(data),
    48  			}
    49  			_, err := req.JSONBody(&txReq)
    50  			if err != nil {
    51  				panic(fmt.Errorf("encode tx errror %v", err))
    52  			}
    53  			d, _ := json.MarshalIndent(&txReq, "", "\t")
    54  			fmt.Println(string(d))
    55  
    56  			str, err := req.String()
    57  			if err != nil {
    58  				fmt.Println(err)
    59  				return
    60  			}
    61  			fmt.Println(str)
    62  		}
    63  	}
    64  }