github.com/igggame/nebulas-go@v2.1.0+incompatible/nebtestkit/cases/rpc/GetTransactionReceipt.test.js (about) 1 'use strict'; 2 var expect = require('chai').expect; 3 var rpc_client = require('./rpc_client/rpc_client.js'); 4 var Wallet = require("nebulas"); 5 6 var protocol_version = '/neb/1.0.0' 7 var node_version = '0.7.0' 8 var server_address = 'localhost:8684'; 9 var coinbase = "n1QZMXSZtW7BUerroSms4axNfyBGyFGkrh5"; 10 var sourceAccount = new Wallet.Account('d80f115bdbba5ef215707a8d7053c16f4e65588fd50b0f83369ad142b99891b5'); 11 var chain_id = 100; 12 var env = 'maintest'; 13 if (env === 'testneb1') { 14 chain_id = 1001; 15 sourceAccount = new Wallet.Account("25a3a441a34658e7a595a0eda222fa43ac51bd223017d17b420674fb6d0a4d52"); 16 coinbase = "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17"; 17 server_address = "35.182.48.19:8684"; 18 19 } else if (env === "testneb2") { 20 chain_id = 1002; 21 sourceAccount = new Wallet.Account("25a3a441a34658e7a595a0eda222fa43ac51bd223017d17b420674fb6d0a4d52"); 22 coinbase = "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17"; 23 server_address = "34.205.26.12:8684"; 24 25 } else if (env === "testneb3") { 26 chain_id = 1003; 27 sourceAccount = new Wallet.Account("25a3a441a34658e7a595a0eda222fa43ac51bd223017d17b420674fb6d0a4d52"); 28 coinbase = "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17"; 29 server_address = "35.177.214.138:8684"; 30 31 } else if (env === "testneb4") { //super node 32 chain_id = 1004; 33 sourceAccount = new Wallet.Account("c75402f6ffe6edcc2c062134b5932151cb39b6486a7beb984792bb9da3f38b9f"); 34 coinbase = "n1EzGmFsVepKduN1U5QFyhLqpzFvM9sRSmG"; 35 server_address = "35.154.108.11:8684"; 36 } else if (env === "testneb4_normalnode"){ 37 chain_id = 1004; 38 sourceAccount = new Wallet.Account("c75402f6ffe6edcc2c062134b5932151cb39b6486a7beb984792bb9da3f38b9f"); 39 coinbase = "n1EzGmFsVepKduN1U5QFyhLqpzFvM9sRSmG"; 40 server_address = "18.197.107.228:8684"; 41 } else if (env === "local") { 42 chain_id = 100; 43 sourceAccount = new Wallet.Account("d80f115bdbba5ef215707a8d7053c16f4e65588fd50b0f83369ad142b99891b5"); 44 coinbase = "n1QZMXSZtW7BUerroSms4axNfyBGyFGkrh5"; 45 server_address = "127.0.0.1:8684"; 46 47 } else if (env === "maintest"){ 48 chain_id = 2; 49 sourceAccount = new Wallet.Account("d2319a8a63b1abcb0cc6d4183198e5d7b264d271f97edf0c76cfdb1f2631848c"); 50 coinbase = "n1dZZnqKGEkb1LHYsZRei1CH6DunTio1j1q"; 51 server_address = "54.149.15.132:8684"; 52 } else { 53 throw new Error("invalid env (" + env + ")."); 54 } 55 56 var api_client; 57 var normalOutput; 58 var txHash; 59 var nonce; 60 61 function testRpc(testInput, testExpect, done) { 62 api_client.GetTransactionReceipt(testInput.rpcInput, function (err, response) { 63 try { 64 if (err) { 65 expect(testExpect.errMsg).to.be.equal(err.details); 66 } else { 67 if (testInput.isNormal) { 68 //TODO:verify response 69 // expect(response.balance).to.be.a("string"); 70 normalOutput = response; 71 } else { 72 if (testExpect.isNormalOutput) { 73 expect(JSON.stringify(response)).to.be.equal(JSON.stringify(normalOutput)); 74 } else { 75 expect(testExpect.isNormalOutput).to.be.equal(false); 76 expect(JSON.stringify(response)).not.be.equal(JSON.stringify(normalOutput)); 77 //TODO: verify response 78 } 79 } 80 81 } 82 done(); 83 } catch (err) { 84 done(err); 85 } 86 }); 87 88 } 89 90 describe('rpc: sendTransaction', function () { 91 before((done) => { 92 var admin_client = rpc_client.new_client(server_address, 'AdminService'); 93 var args = { 94 address: sourceAccount.getAddressString(), 95 passphrase: "passphrase", 96 } 97 admin_client.UnlockAccount(args, (err, resp) => { 98 expect(err).to.be.equal(null); 99 console.log(err); 100 done(err); 101 }) 102 }); 103 104 before((done) => { 105 api_client = rpc_client.new_client(server_address); 106 api_client.GetAccountState({ address: sourceAccount.getAddressString() }, (err, resp) => { 107 expect(err).to.be.equal(null); 108 nonce = parseInt(resp.nonce); 109 done(err); 110 }); 111 }) 112 113 before((done) => { 114 nonce = nonce + 1; 115 var args = { 116 from: sourceAccount.getAddressString(), 117 to: coinbase, 118 value: "1", 119 nonce: nonce, 120 gas_price: "1000000", 121 gas_limit: "200000", 122 }, 123 admin_client = rpc_client.new_client(server_address, "AdminService"); 124 admin_client.SendTransaction(args, (err, resp) => { 125 expect(err).to.be.equal(null); 126 txHash = resp.txhash; 127 done(err); 128 }); 129 }); 130 131 it('normal', function (done) { 132 nonce = nonce + 1; 133 var testInput = { 134 rpcInput: { 135 hash: txHash, 136 }, 137 isNormal: true 138 } 139 140 var testExpect = { 141 isNormalOutput: true, 142 } 143 144 testRpc(testInput, testExpect, done); 145 }); 146 147 it('hash is not exist', function (done) { 148 nonce = nonce + 1; 149 var testInput = { 150 rpcInput: { 151 hash: '1c4d8ddcf2e0b41b87df09684a594468d7750e87b72f5e77320e02781a05170c', 152 }, 153 isNormal: false 154 } 155 156 var testExpect = { 157 errMsg: 'transaction not found' 158 } 159 160 testRpc(testInput, testExpect, done); 161 }); 162 163 it('hash is empty', function (done) { 164 nonce = nonce + 1; 165 var testInput = { 166 rpcInput: { 167 168 }, 169 isNormal: false 170 } 171 172 var testExpect = { 173 isNormalOutput: true, 174 errMsg: 'invalid argument(s)' 175 } 176 177 testRpc(testInput, testExpect, done); 178 }); 179 180 it('tx is null', function (done) { 181 nonce = nonce + 1; 182 var testInput = { 183 rpcInput: { 184 hash: "", 185 }, 186 isNormal: false 187 } 188 189 var testExpect = { 190 isNormalOutput: true, 191 errMsg: 'invalid argument(s)' 192 } 193 194 testRpc(testInput, testExpect, done); 195 }); 196 197 it('hash is different length', function (done) { 198 nonce = nonce + 1; 199 var testInput = { 200 rpcInput: { 201 hash: "sfhadfhlahdflsh", 202 }, 203 isNormal: false 204 } 205 206 var testExpect = { 207 isNormalOutput: true, 208 errMsg: 'encoding/hex: invalid byte: U+0073 \'s\'' 209 } 210 211 testRpc(testInput, testExpect, done); 212 }) 213 214 it('hash is invalid', function (done) { 215 nonce = nonce + 1; 216 var testInput = { 217 rpcInput: { 218 hash: "1c4d8ddcf2e0b41b87df09684a@94468d7750e87b72f5e77320e0278aa05170c", 219 }, 220 isNormal: false 221 } 222 223 var testExpect = { 224 isNormalOutput: true, 225 errMsg: "encoding/hex: invalid byte: U+0040 '@'" 226 } 227 228 testRpc(testInput, testExpect, done); 229 }) 230 });