github.com/igggame/nebulas-go@v2.1.0+incompatible/nebtestkit/cases/rpc/admin.SignTransaction.test.js (about) 1 'use strict'; 2 3 var expect = require('chai').expect; 4 var rpc_client = require('./rpc_client/rpc_client.js'); 5 6 7 var coinbase, 8 server_address; 9 10 var env = process.env.NET || 'local'; 11 if (env === 'local') { 12 server_address = 'localhost:8684'; 13 coinbase = "n1QZMXSZtW7BUerroSms4axNfyBGyFGkrh5"; 14 } else if (env === 'testneb1') { 15 server_address = '35.182.48.19:8684'; 16 coinbase = "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d"; 17 } else if (env === "testneb2") { 18 server_address = "34.205.26.12:8684"; 19 coinbase = "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d"; 20 } 21 22 var client, 23 address; 24 25 function testSignTransaction(testInput, testExpect, done) { 26 client.SignTransaction(testInput.args, (err, resp) => { 27 try { 28 expect(!!err).to.equal(testExpect.hasError); 29 30 if (err) { 31 console.log(JSON.stringify(err)); 32 expect(err).have.property('details').equal(testExpect.errorMsg); 33 } else { 34 console.log(JSON.stringify(resp)); 35 expect(resp).to.have.property('data'); 36 } 37 done(); 38 } catch (err) { 39 done(err); 40 } 41 }); 42 } 43 44 describe("rpc: SignTransaction", () => { 45 before((done) => { 46 client = rpc_client.new_client(server_address, 'AdminService'); 47 48 try { 49 client.NewAccount({passphrase: "passphrase"}, (err, resp) => { 50 expect(!!err).to.be.false; 51 expect(resp).to.have.property('address'); 52 address = resp.address; 53 console.log("create new account: " + address); 54 55 client.UnlockAccount({ 56 address: address, 57 passphrase: "passphrase" 58 }, (err, resp) => { 59 try { 60 expect(resp).to.have.property('result').equal(true); 61 done(); 62 } catch(err) { 63 console.log("unlock account failed"); 64 done(err); 65 } 66 }); 67 }); 68 } catch(err) { 69 done(err) 70 } 71 }); 72 73 it('1. normal', done => { 74 var testInput = { 75 args: { 76 from: address, 77 to: "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d", 78 value: "123", 79 nonce: "10000", 80 gas_price: "1000000", 81 gas_limit: "1000000", 82 contract: {} 83 } 84 } 85 86 var testExpect = { 87 hasError: false, 88 errorMsg: "", 89 90 } 91 92 testSignTransaction(testInput, testExpect, done) 93 }); 94 95 it('2. `to` illegal', done => { 96 var testInput = { 97 args: { 98 from: address, 99 to: "faaaa", 100 value: "", 101 nonce: "10000", 102 gas_price: "1000000", 103 gas_limit: "1000000", 104 contract: {} 105 } 106 } 107 108 var testExpect = { 109 hasError: true, 110 errorMsg: "address: invalid address", 111 112 } 113 114 testSignTransaction(testInput, testExpect, done) 115 }); 116 117 it('3. `to` empty', done => { 118 var testInput = { 119 args: { 120 from: address, 121 to: "", 122 value: "", 123 nonce: "10000", 124 gas_price: "1000000", 125 gas_limit: "1000000", 126 contract: {} 127 } 128 } 129 130 var testExpect = { 131 hasError: true, 132 errorMsg: "address: invalid address", 133 134 } 135 136 testSignTransaction(testInput, testExpect, done) 137 }); 138 139 it('4. `value` empty', done => { 140 var testInput = { 141 args: { 142 from: address, 143 to: "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d", 144 value: "", 145 nonce: "10000", 146 gas_price: "1000000", 147 gas_limit: "1000000", 148 contract: {} 149 } 150 } 151 152 var testExpect = { 153 hasError: true, 154 errorMsg: "invalid value", 155 156 } 157 158 testSignTransaction(testInput, testExpect, done) 159 }); 160 161 it('5. `value` alpha', done => { 162 var testInput = { 163 args: { 164 from: address, 165 to: "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d", 166 value: "abc", 167 nonce: "10000", 168 gas_price: "1000000", 169 gas_limit: "1000000", 170 contract: {} 171 } 172 } 173 174 var testExpect = { 175 hasError: true, 176 errorMsg: "invalid value", 177 178 } 179 180 testSignTransaction(testInput, testExpect, done) 181 }); 182 183 it('6. `value` neg number', done => { 184 var testInput = { 185 args: { 186 from: address, 187 to: "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d", 188 value: "-123", 189 nonce: "10000", 190 gas_price: "1000000", 191 gas_limit: "1000000", 192 contract: {} 193 } 194 } 195 196 var testExpect = { 197 hasError: true, 198 errorMsg: "invalid value", 199 200 } 201 202 testSignTransaction(testInput, testExpect, done) 203 }); 204 205 it('7. `nonce` alpha', done => { 206 var testInput = { 207 args: { 208 from: address, 209 to: "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d", 210 value: "123", 211 nonce: "abasdx", 212 gas_price: "1000000", 213 gas_limit: "1000000", 214 contract: {} 215 } 216 } 217 218 var testExpect = { 219 hasError: false, 220 errorMsg: "", 221 222 } 223 224 testSignTransaction(testInput, testExpect, done) 225 }); 226 227 it('8. `nonce` neg number', done => { 228 var testInput = { 229 args: { 230 from: address, 231 to: "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d", 232 value: "123", 233 nonce: "-10000", 234 gas_price: "1000000", 235 gas_limit: "1000000", 236 contract: {} 237 } 238 } 239 240 var testExpect = { 241 hasError: false, 242 errorMsg: "", 243 244 } 245 246 testSignTransaction(testInput, testExpect, done) 247 }); 248 249 it('9. `gas_price` empty', done => { 250 var testInput = { 251 args: { 252 from: address, 253 to: "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d", 254 value: "123", 255 nonce: "10000", 256 gas_price: "", 257 gas_limit: "1000000", 258 contract: {} 259 } 260 } 261 262 var testExpect = { 263 hasError: true, 264 errorMsg: "invalid gasPrice", 265 266 } 267 268 testSignTransaction(testInput, testExpect, done) 269 }); 270 271 it('10. `gas_price` alpha', done => { 272 var testInput = { 273 args: { 274 from: address, 275 to: "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d", 276 value: "123", 277 nonce: "10000", 278 gas_price: "abcxz", 279 gas_limit: "1000000", 280 contract: {} 281 } 282 } 283 284 var testExpect = { 285 hasError: true, 286 errorMsg: "invalid gasPrice", 287 288 } 289 290 testSignTransaction(testInput, testExpect, done) 291 }); 292 293 it('11. `gas_price` negative', done => { 294 var testInput = { 295 args: { 296 from: address, 297 to: "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d", 298 value: "123", 299 nonce: "10000", 300 gas_price: "-10000", 301 gas_limit: "1000000", 302 contract: {} 303 } 304 } 305 306 var testExpect = { 307 hasError: true, 308 errorMsg: "invalid gasPrice", 309 310 } 311 312 testSignTransaction(testInput, testExpect, done) 313 }); 314 315 it('12. `gas_limit` empty', done => { 316 var testInput = { 317 args: { 318 from: address, 319 to: "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d", 320 value: "123", 321 nonce: "10000", 322 gas_price: "1000000", 323 gas_limit: "", 324 contract: {} 325 } 326 } 327 328 var testExpect = { 329 hasError: true, 330 errorMsg: "invalid gasLimit", 331 332 } 333 334 testSignTransaction(testInput, testExpect, done) 335 }); 336 337 it('13. `gas_limit` alpha', done => { 338 var testInput = { 339 args: { 340 from: address, 341 to: "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d", 342 value: "123", 343 nonce: "10000", 344 gas_price: "1000000", 345 gas_limit: "aaz", 346 contract: {} 347 } 348 } 349 350 var testExpect = { 351 hasError: true, 352 errorMsg: "invalid gasLimit", 353 354 } 355 356 testSignTransaction(testInput, testExpect, done) 357 }); 358 359 it('14. `gas_limit` negative', done => { 360 var testInput = { 361 args: { 362 from: address, 363 to: "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d", 364 value: "123", 365 nonce: "10000", 366 gas_price: "1000000", 367 gas_limit: "-10000", 368 contract: {} 369 } 370 } 371 372 var testExpect = { 373 hasError: true, 374 errorMsg: "invalid gasLimit", 375 376 } 377 378 testSignTransaction(testInput, testExpect, done) 379 }); 380 381 it('15. `contract` empty', done => { 382 var testInput = { 383 args: { 384 from: address, 385 to: "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d", 386 value: "123", 387 nonce: "10000", 388 gas_price: "1000000", 389 gas_limit: "1000000", 390 contract: {} 391 } 392 } 393 394 var testExpect = { 395 hasError: false, 396 errorMsg: "", 397 398 } 399 400 testSignTransaction(testInput, testExpect, done) 401 }); 402 403 it('16. `contract`', done => { 404 var testInput = { 405 args: { 406 from: address, 407 to: "0b9cd051a6d7129ab44b17833c63fe4abead40c3714cde6d", 408 value: "123", 409 nonce: "10000", 410 gas_price: "1000000", 411 gas_limit: "1000000", 412 contract: { 413 "function": "save", 414 } 415 } 416 } 417 418 var testExpect = { 419 hasError: false, 420 errorMsg: "", 421 422 } 423 424 testSignTransaction(testInput, testExpect, done) 425 }); 426 });