github.com/igggame/nebulas-go@v2.1.0+incompatible/nebtestkit/cases/rpc/getAccountState.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 var Account = Wallet.Account; 6 var protocol_version = '/neb/1.0.0' 7 var node_version = '0.7.0'; 8 9 10 var server_address = 'localhost:8684'; 11 var coinbase = "eb31ad2d8a89a0ca6935c308d5425730430bc2d63f2573b8"; 12 var sourceAccount; 13 var chain_id = 100; 14 var env = 'maintest'; 15 16 if (env === 'testneb1') { 17 chain_id = 1001; 18 sourceAccount = new Wallet.Account("25a3a441a34658e7a595a0eda222fa43ac51bd223017d17b420674fb6d0a4d52"); 19 coinbase = "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17"; 20 server_address = "35.182.48.19:8684"; 21 22 } else if (env === "testneb2") { 23 chain_id = 1002; 24 sourceAccount = new Wallet.Account("25a3a441a34658e7a595a0eda222fa43ac51bd223017d17b420674fb6d0a4d52"); 25 coinbase = "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17"; 26 server_address = "34.205.26.12:8684"; 27 28 } else if (env === "testneb3") { 29 chain_id = 1003; 30 sourceAccount = new Wallet.Account("25a3a441a34658e7a595a0eda222fa43ac51bd223017d17b420674fb6d0a4d52"); 31 coinbase = "n1SAeQRVn33bamxN4ehWUT7JGdxipwn8b17"; 32 server_address = "35.177.214.138:8684"; 33 34 } else if (env === "testneb4") { //super node 35 chain_id = 1004; 36 sourceAccount = new Wallet.Account("c75402f6ffe6edcc2c062134b5932151cb39b6486a7beb984792bb9da3f38b9f"); 37 coinbase = "n1EzGmFsVepKduN1U5QFyhLqpzFvM9sRSmG"; 38 server_address = "35.154.108.11:8684"; 39 } else if (env === "testneb4_normalnode"){ 40 chain_id = 1004; 41 sourceAccount = new Wallet.Account("c75402f6ffe6edcc2c062134b5932151cb39b6486a7beb984792bb9da3f38b9f"); 42 coinbase = "n1EzGmFsVepKduN1U5QFyhLqpzFvM9sRSmG"; 43 server_address = "18.197.107.228:8684"; 44 } else if (env === "local") { 45 chain_id = 100; 46 sourceAccount = new Wallet.Account("d80f115bdbba5ef215707a8d7053c16f4e65588fd50b0f83369ad142b99891b5"); 47 coinbase = "n1QZMXSZtW7BUerroSms4axNfyBGyFGkrh5"; 48 server_address = "127.0.0.1:8684"; 49 50 } else if (env === "maintest"){ 51 chain_id = 2; 52 sourceAccount = new Wallet.Account("d2319a8a63b1abcb0cc6d4183198e5d7b264d271f97edf0c76cfdb1f2631848c"); 53 coinbase = "n1dZZnqKGEkb1LHYsZRei1CH6DunTio1j1q"; 54 server_address = "54.149.15.132:8684"; 55 } else { 56 throw new Error("invalid env (" + env + ")."); 57 } 58 59 var client; 60 var normalOutput; 61 62 function testRpc(testInput, testExpect, done) { 63 client.getAccountState(testInput.rpcInput, function (err, response) { 64 if (err != null) { 65 try { 66 expect(testExpect.errMsg).to.be.equal(err.details); 67 } catch (err) { 68 console.log(err); 69 done(err) 70 return; 71 } 72 console.log(err); 73 done(); 74 return; 75 } else { 76 try { 77 if (testInput.isNormal) { 78 normalOutput = response; 79 } else { 80 if (testExpect.isNormalOutput) { 81 expect(JSON.stringify(response)).to.be.equal(JSON.stringify(normalOutput)); 82 } else { 83 expect(testExpect.isNormalOutput).to.be.equal(false); 84 expect(JSON.stringify(response)).not.be.equal(JSON.stringify(normalOutput)); 85 expect(response.balance).to.be.a("string"); 86 //In JS, uint64 is converted to string 87 expect(response.nonce).to.be.a('string'); 88 } 89 } 90 } catch (err 91 ) { 92 done(err); 93 return; 94 }; 95 } 96 done(); 97 return; 98 }); 99 100 } 101 102 describe('rpc: getAccountState', 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 address: coinbase, 111 height: 0 112 }, 113 isNormal: true 114 } 115 116 var testExpect = { 117 isNormalOutput: true 118 } 119 120 testRpc(testInput, testExpect, done); 121 }) 122 123 console.log(Account.NewAccount().getAddressString()); 124 it('address is not exist', function (done) { 125 var testInput = { 126 rpcInput: { 127 address: Account.NewAccount().getAddressString(), 128 height: 0 129 }, 130 isNormal: false 131 } 132 133 var testExpect = { 134 isNormalOutput: false, 135 } 136 137 testRpc(testInput, testExpect, done); 138 }); 139 140 it('address is invalid', function (done) { 141 var testInput = { 142 rpcInput: { 143 address: 'b7d83b44@@3719220ec54cdb9f54c0202de68f1ebcb927b4f', 144 height: 0 145 }, 146 isNormal: false 147 } 148 149 var testExpect = { 150 isNormalOutput: false, 151 errMsg: 'address: invalid address format' 152 } 153 154 testRpc(testInput, testExpect, done); 155 }); 156 157 it('address is null', function (done) { 158 var testInput = { 159 rpcInput: { 160 address: '', 161 height: 0 162 }, 163 isNormal: false 164 } 165 166 var testExpect = { 167 isNormalOutput: false, 168 errMsg: 'address: invalid address format' 169 } 170 171 testRpc(testInput, testExpect, done); 172 }); 173 174 it('address is empty', function (done) { 175 var testInput = { 176 rpcInput: { 177 height: 0 178 }, 179 isNormal: false 180 } 181 182 var testExpect = { 183 isNormalOutput: false, 184 errMsg: 'address: invalid address format' 185 } 186 187 testRpc(testInput, testExpect, done); 188 }) 189 190 it('height is empty', function (done) { 191 var testInput = { 192 rpcInput: { 193 address: coinbase, 194 }, 195 isNormal: false 196 } 197 198 var testExpect = { 199 isNormalOutput: true 200 } 201 202 testRpc(testInput, testExpect, done); 203 }) 204 205 it('height is negtive', function (done) { 206 var testInput = { 207 rpcInput: { 208 address: coinbase, 209 height: -1 210 }, 211 isNormal: false 212 } 213 214 var testExpect = { 215 isNormalOutput: true//todo: to check 216 } 217 218 testRpc(testInput, testExpect, done); 219 }) 220 221 it('height out of max', function (done) { 222 var testInput = { 223 rpcInput: { 224 address: coinbase, 225 height: 1111111111111111111111111111111111111111111111111111111 226 }, 227 isNormal: false 228 } 229 230 var testExpect = { 231 errMsg: 'block not found' 232 } 233 234 testRpc(testInput, testExpect, done); 235 }) 236 237 it('height is postive', function (done) { 238 var testInput = { 239 rpcInput: { 240 address: coinbase, 241 height: 2 242 }, 243 isNormal: false 244 } 245 246 var testExpect = { 247 isNormalOutput: false 248 } 249 250 testRpc(testInput, testExpect, done); 251 }) 252 253 });