github.com/igggame/nebulas-go@v2.1.0+incompatible/nebtestkit/cases/rpc/getBlockByHash.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 sourceAccount; 7 var protocol_version = '/neb/1.0.0' 8 var node_version = '0.7.0' 9 var server_address = 'localhost:8684'; 10 var coinbase = "eb31ad2d8a89a0ca6935c308d5425730430bc2d63f2573b8"; 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 client; 57 var normalOutput; 58 59 function testRpc(testInput, testExpect, done) { 60 client.getBlockByHash(testInput.rpcInput, function (err, response) { 61 if (err != null) { 62 try { 63 expect(testExpect.errMsg).to.be.equal(err.details); 64 } catch (err) { 65 console.log(err); 66 done(err) 67 return; 68 } 69 console.log(err); 70 done(); 71 return; 72 } else { 73 try { 74 if (testInput.isNormal) { 75 console.log(response); 76 //TODO:verify response 77 // expect(response.balance).to.be.a("string"); 78 normalOutput = response; 79 expect(response.coinbase.length).to.be.equal(35); 80 } else { 81 if (testExpect.isNormalOutput) { 82 console.log(response); 83 expect(JSON.stringify(response)).to.be.equal(JSON.stringify(normalOutput)); 84 expect(response.coinbase.length).to.be.equal(35); 85 } else { 86 expect(testExpect.isNormalOutput).to.be.equal(false); 87 expect(JSON.stringify(response)).not.be.equal(JSON.stringify(normalOutput)); 88 } 89 } 90 } catch (err 91 ) { 92 done(err); 93 return; 94 }; 95 } 96 done(); 97 return; 98 }); 99 100 } 101 102 describe('rpc: getBlockByHash', function () { 103 before(function () { 104 client = rpc_client.new_client(server_address); 105 }); 106 107 it('normal rpc', function (done) { 108 var testInput = { 109 rpcInput: { 110 hash: '0000000000000000000000000000000000000000000000000000000000000000' 111 }, 112 isNormal: true 113 } 114 115 var testExpect = { 116 isNormalOutput: true 117 } 118 119 testRpc(testInput, testExpect, done); 120 }) 121 122 it('hash is valid(too short)', function (done) { 123 var testInput = { 124 rpcInput: { 125 hash: "013", 126 }, 127 isNormal: false 128 } 129 130 var testExpect = { 131 errMsg: 'encoding/hex: odd length hex string' 132 } 133 134 testRpc(testInput, testExpect, done); 135 }) 136 137 it('hash is too long', function (done) { 138 var testInput = { 139 rpcInput: { 140 hash: '11111111111111333333333311111111111111111111111111111111111111111' 141 }, 142 isNormal: false 143 } 144 145 var testExpect = { 146 errMsg: 'encoding/hex: odd length hex string' 147 } 148 149 testRpc(testInput, testExpect, done); 150 }) 151 152 it('hash is null', function (done) { 153 var testInput = { 154 rpcInput: { 155 hash: "" 156 }, 157 isNormal: false 158 } 159 160 var testExpect = { 161 errMsg: 'block not found' 162 } 163 164 testRpc(testInput, testExpect, done); 165 }) 166 167 it('hash is empty', function (done) { 168 var testInput = { 169 rpcInput: { 170 }, 171 isNormal: false 172 } 173 174 var testExpect = { 175 errMsg: 'block not found' 176 } 177 178 testRpc(testInput, testExpect, done); 179 }) 180 181 it('hash is not exist', function (done) { 182 var testInput = { 183 rpcInput: { 184 hash: '0100000000000000000000000000000000000000000000000000000000000000' 185 }, 186 isNormal: true 187 } 188 189 var testExpect = { 190 errMsg: 'block not found' 191 } 192 193 testRpc(testInput, testExpect, done); 194 }) 195 196 });