github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/http/router/rennbon_test.go (about)

     1  package router_test
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/sixexorg/magnetic-ring/common/sink"
     8  	"github.com/sixexorg/magnetic-ring/core/mainchain/types"
     9  	orgtypes "github.com/sixexorg/magnetic-ring/core/orgchain/types"
    10  	"github.com/sixexorg/magnetic-ring/http/cli"
    11  	"github.com/sixexorg/magnetic-ring/http/req"
    12  	"github.com/sixexorg/magnetic-ring/mock"
    13  )
    14  
    15  func TestMainChain(t *testing.T) {
    16  	var (
    17  		//from = mock.AccountNormal_1.Addr.ToString()
    18  		from = "ct1j95gw45wnmdazmgpux7wc25tTrT5ExXg"
    19  		to   = "ct1b3cznr6mAmE7Ab4cewd6xe6rtctjpgfv"
    20  
    21  		nonce, leagueNonce uint64 = 1, 2
    22  
    23  		tp types.TransactionType = types.JoinLeague
    24  	)
    25  	/*TransferBox
    26  	GetBonus
    27  	RecycleMinbox
    28  	TransferEnergy
    29  	CreateLeague
    30  	JoinLeague
    31  	EnergyToLeague */
    32  	//nonce, leagueNonce uint64, from, to, league string, tp maintypes.TransactionType)
    33  	tx := transactionBuild(nonce, leagueNonce, from, to, leagueId, tp)
    34  	fmt.Printf("☺️ ☺️ ☺️ ☺️ ☺️ -->%s\n",leagueId)
    35  	err := tx.ToRaw()
    36  	if err != nil {
    37  		panic(err)
    38  	}
    39  	req := req.ReqSendTx{
    40  		Raw: tx.Raw,
    41  	}
    42  	fullurl := fmt.Sprintf("%s/block/sendtx", baseurl)
    43  	resp, err := cli.HttpSend(fullurl, req)
    44  	if err != nil {
    45  		t.Log(err)
    46  		return
    47  	}
    48  	t.Logf("txhash=%s,\n", resp)
    49  }
    50  func TestOrgChain(t *testing.T) {
    51  	var (
    52  		nonce     uint64                   = 4
    53  		from                               = mock.AccountNormal_1.Addr.ToString()
    54  		to                                 = "ct0fHcR19s2nDaHxR3CVdUyYxHgsjzp8wrt"
    55  		tp        orgtypes.TransactionType = orgtypes.ReplyVote
    56  		voteReply                          = orgtypes.Agree
    57  		txhash                             = "52fcc88ab3521b1fbcc0cf2e7132cb67540c3826b390dcbc0fa6c7d744c7d149"
    58  		//"52fcc88ab3521b1fbcc0cf2e7132cb67540c3826b390dcbc0fa6c7d744c7d149" //"eb7e7a23e70cc64c2e9d5fc8a854dd5d5ebc2c195c12eb9f9db0d220c84e258d"
    59  	)
    60  	/*TransferUT
    61  	ReplyVote
    62  	VoteIncreaseUT
    63  	GetBonus
    64  	Join
    65  	Leave
    66  	EnergyFromMain
    67  	EnergyToMain   */
    68  	//nonce, leagueNonce uint64, from, to, league string, tp maintypes.TransactionType)
    69  	tx := orgTransactionBuild(nonce, from, to, tp, txhash, voteReply)
    70  	err := tx.ToRaw()
    71  	fmt.Println("hash ", tx.Hash())
    72  	sk := sink.NewZeroCopySource(tx.Raw)
    73  	txTmp := &orgtypes.Transaction{}
    74  	err = txTmp.Deserialization(sk)
    75  	if err != nil {
    76  		fmt.Println(err)
    77  		return
    78  	}
    79  	if err != nil {
    80  		t.Errorf("toraw err-->%v\n", err)
    81  		return
    82  	}
    83  	//ct2aQyCjVfJ5vgh8x8xb2yRbTu6741Yg8u7
    84  	fmt.Printf("••••••••••••••••••••••••••••herhe-->%s\n", leagueId)
    85  
    86  	req := req.ReqSendTx{
    87  		LeagueId: leagueId,
    88  		Raw:      tx.Raw,
    89  	}
    90  	fullurl := fmt.Sprintf("%s/block/sendsubtx", baseurl)
    91  	resp, err := cli.HttpSend(fullurl, req)
    92  	if err != nil {
    93  		t.Log(err)
    94  		return
    95  	}
    96  	t.Logf("txhash=%s,\n", resp)
    97  }