github.com/cheng762/platon-go@v1.8.17-0.20190529111256-7deff2d7be26/cmd/ctool/core/utils_test.go (about) 1 package core 2 3 import ( 4 "bytes" 5 "fmt" 6 "github.com/PlatONnetwork/PlatON-Go/common" 7 "testing" 8 ) 9 10 func TestParseConfig(t *testing.T) { 11 //param := TxParams{} 12 param := DeployParams{} 13 parseConfigJson(configPath) 14 15 fmt.Println(param.Gas) 16 fmt.Println(param.GasPrice) 17 fmt.Println(param.From) 18 } 19 20 /*func TestParseFuncFromAbi(t *testing.T) { 21 22 dir, _ := os.Getwd() 23 filePath := dir + "/demo01.cpp.abi.json" 24 funcDesc, _ := parseFuncFromAbi(filePath, "transfer") 25 26 fmt.Println(funcDesc.Name) 27 fmt.Println(funcDesc.Inputs) 28 fmt.Println(funcDesc.Outputs) 29 fmt.Println(len(funcDesc.Constant)) 30 } 31 32 func TestParseAbiFromJson(t *testing.T) { 33 34 dir, _ := os.Getwd() 35 filePath := dir + "/demo01.cpp.abi.json" 36 a, e := parseAbiFromJson(filePath) 37 if e != nil { 38 t.Fatalf("parse abi json error! \n, %s", e.Error()) 39 } 40 fmt.Println(a) 41 marshal, _ := json.Marshal(a) 42 fmt.Println(string(marshal)) 43 } 44 45 func TestHttpPostTransfer(t *testing.T) { 46 //params := TxParams{ 47 // From:"0xfb8c2fa47e84fbde43c97a0859557a36a5fb285b", 48 // To:"0x9f75627b1436b506eafc96bf70bcd2ff88f715e2", 49 // Value:"0x2710", 50 // Gas: "0x76c0", 51 // GasPrice:"0x9184e72a000", 52 //} 53 //url := "http://localhost:8545" 54 param := JsonParam{ 55 Jsonrpc: "2.0", 56 Method: "eth_sendTransaction", 57 //Params:[]TxParams{}, 58 Id: 1, 59 } 60 s, e := HttpPost(param) 61 if e != nil { 62 t.Fatal("test http post error .\n" + e.Error()) 63 } 64 fmt.Println(s) 65 66 }*/ 67 68 /*func TestHttpPostDeploy(t *testing.T) { 69 deployParams := DeployParams{ 70 From: "0xfb8c2fa47e84fbde43c97a0859557a36a5fb285b", 71 Gas: "0x400000", 72 GasPrice: "0x9184e72a000", 73 } 74 75 params := make([]interface{}, 1) 76 params[0] = deployParams 77 param := JsonParam{ 78 Jsonrpc: "2.0", 79 Method: "eth_sendTransaction", 80 Params: params, 81 Id: 1, 82 } 83 84 r, e := HttpPost(param) 85 if e != nil { 86 t.Fatal("test http post error .\n" + e.Error()) 87 } 88 89 var resp = Response{} 90 err := json.Unmarshal([]byte(r), &resp) 91 if err != nil { 92 t.Fatalf("parse result error ! \n %s", err.Error()) 93 } 94 95 if resp.Error.Code != 0 { 96 t.Fatalf("send transaction error ,error:%v", resp.Error.Message) 97 } 98 fmt.Printf("trasaction hash: %s\n", resp.Result) 99 100 // Get transaction receipt according to result 101 ch := make(chan string, 1) 102 go GetTransactionReceipt(resp.Result, ch) 103 104 // Then, we use the timeout channel 105 select { 106 case address := <-ch: 107 fmt.Printf("contract address:%s\n", address) 108 case <-time.After(time.Second * 100): 109 fmt.Printf("get contract receipt timeout...more than 100 second.\n") 110 } 111 112 } 113 114 func TestHttpCallContact(t *testing.T) { 115 116 //url := "http://localhost:8545" 117 param1 := uint(33) 118 b := new(bytes.Buffer) 119 rlp.Encode(b, param1) 120 121 params := TxParams{ 122 From: "0xfb8c2fa47e84fbde43c97a0859557a36a5fb285b", 123 To: "0xace6bdba54c8c359e70f541bfc1cabaf0244b916", 124 Value: "0x2710", 125 Gas: "0x76c00", 126 GasPrice: "0x9184e72a000", 127 //Data:"0x60fe47b10000000000000000000000000000000000000000000000000000000000000011", 128 } 129 130 param := JsonParam{ 131 Jsonrpc: "2.0", 132 Method: "eth_sendTransaction", 133 Params: []TxParams{params}, 134 Id: 1, 135 } 136 paramJson, _ := json.Marshal(param) 137 fmt.Println(string(paramJson)) 138 s, e := HttpPost(param) 139 if e != nil { 140 t.Fatal("test http post error .\n" + e.Error()) 141 } 142 fmt.Println(s) 143 144 }*/ 145 146 func TestGetFuncParam(t *testing.T) { 147 //f := "set(\"1\",\"b\",1.2)" 148 f := "set()" 149 s, strings := GetFuncNameAndParams(f) 150 fmt.Println(s) 151 fmt.Println(len(strings)) 152 153 //funcName := string(f[0:strings.Index(f, "(")]) 154 //fmt.Println(funcName) 155 // 156 //paramString := string(f[strings.Index(f, "(")+1 : strings.LastIndex(f, ")")]) 157 //fmt.Println(paramString) 158 // 159 //params := strings.Split(paramString, ",") 160 //for _, param := range params { 161 // if strings.HasPrefix(param, "\"") { 162 // i, err := strconv.Atoi(param[strings.Index(param, "\"")+1 : strings.LastIndex(param, "\"")]) 163 // fmt.Println(err) 164 // fmt.Println(i) 165 // } 166 //} 167 //fmt.Println(params) 168 } 169 170 func TestAAA(t *testing.T) { 171 //dir := "D:\\resource\\platon\\contract\\Platon-contract\\build\\user\\wuwei\\wuwei.cpp.abi.json" 172 //funcName:= "transfer" 173 //funcParams := "transfer(\"0x60ceca9c\",\"0x60ceca\",100)" 174 //encodeParam(dir,funcName,funcParams) 175 176 byts := []byte("0x00000000000000000000000000000000000000c5") 177 fmt.Print(byts) 178 //fmt.Printf(string(byts)) 179 180 //toAddr :=common.Address{} 181 //toAddr.SetBytes([]byte("0x43355c787c50b647c425f594b441d4bd751951c1")) 182 //fmt.Printf(toAddr.Hex()) 183 // 184 // 185 //toAddr2 :=common.Address{} 186 //decode, _ := hexutil.Decode("0x43355c787c50b647c425f594b441d4bd751951c1") 187 //toAddr2.SetBytes(decode) 188 //fmt.Printf(toAddr2.Hex()) 189 190 } 191 func TestBBB(t *testing.T) { 192 dir := "D:\\resource\\platon\\contract\\Platon-contract\\temp\\contracta.cpp.abi.json" 193 funcName := "atransfer2" 194 funcParams := "atransfer2(\"eeeeeee\",\"ffffff\",3333)" 195 //funcParams := "transfer(\"0x43355c787c50b647c425f594b441d4bd751951c1\")" 196 197 encodeParam(dir, funcName, funcParams) 198 199 } 200 201 func TestCCC(t *testing.T) { 202 b := common.BytesToHash(common.Int64ToBytes(int64(1231))) 203 fmt.Println(bytes.Equal(b[:24], make([]byte, 24))) 204 fmt.Println(b[24:]) 205 fmt.Print(common.Int64ToBytes(int64(1231))) 206 207 }