github.com/igggame/nebulas-go@v2.1.0+incompatible/nebtestkit/cases/rpc/admin.SendTransactionWithPassphrase.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 = "eb31ad2d8a89a0ca6935c308d5425730430bc2d63f2573b8"; 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 toAddress; 25 26 function testSendTransactionWithPassphrase(testInput, testExpect, done) { 27 try { 28 client.SendTransactionWithPassphrase(testInput, (err, resp) => { 29 try { 30 // console.log(JSON.stringify(err)); 31 expect(!!err).to.equal(testExpect.hasError); 32 33 if (err) { 34 console.log(JSON.stringify(err)); 35 expect(err).have.property('details').equal(testExpect.errorMsg); 36 } else { 37 console.log(JSON.stringify(resp)); 38 expect(resp).to.have.property('txhash'); 39 expect(resp).to.have.property('contract_address'); 40 } 41 done(); 42 } catch (err) { 43 done(err); 44 } 45 }); 46 } catch (err) { 47 try { 48 expect(testExpect.hasError).to.be.true; 49 expect(err.toString()).to.have.string(testExpect.cannotExecuteError); 50 done(); 51 } catch(er) { 52 done(err) 53 } 54 } 55 } 56 57 describe("rpc: SendTransactionWithPassphrase", () => { 58 before((done) => { 59 client = rpc_client.new_client(server_address, 'AdminService'); 60 61 try { 62 client.NewAccount({passphrase: "passphrase"}, (err, resp) => { 63 expect(!!err).to.be.false; 64 expect(resp).to.have.property('address'); 65 address = resp.address; 66 console.log("create new `from` account: " + address); 67 68 client.NewAccount({passphrase: "passphraseto"}, (err, resp) => { 69 expect(!!err).to.be.false; 70 expect(resp).to.have.property('address'); 71 toAddress = resp.address; 72 console.log("create new `to` account: " + toAddress); 73 done(); 74 }); 75 }); 76 } catch(err) { 77 done(err) 78 } 79 }); 80 81 it('1. normal', done => { 82 var testInput = { 83 transaction: { 84 from: address, 85 to: toAddress, 86 value: "123", 87 nonce: "10000", 88 gas_price: "1000000", 89 gas_limit: "1000000", 90 contract: {} 91 }, 92 passphrase: 'passphrase' 93 } 94 95 var testExpect = { 96 hasError: false 97 } 98 99 testSendTransactionWithPassphrase(testInput, testExpect, done) 100 }); 101 102 it('2. nonexistent `from`', done => { 103 var testInput = { 104 transaction: { 105 from: "eb31ad2d8a89a0ca6935c308d5425730430bc2d63f2573b8", 106 to: toAddress, 107 value: "123", 108 nonce: "10000", 109 gas_price: "1000000", 110 gas_limit: "1000000", 111 contract: {} 112 }, 113 passphrase: 'passphrase' 114 } 115 116 var testExpect = { 117 hasError: true, 118 errorMsg: "address not find", 119 120 } 121 122 testSendTransactionWithPassphrase(testInput, testExpect, done) 123 }); 124 125 it('3. illegal `from`', done => { 126 var testInput = { 127 transaction: { 128 from: "asfas", 129 to: toAddress, 130 value: "123", 131 nonce: "10000", 132 gas_price: "1000000", 133 gas_limit: "1000000", 134 contract: {} 135 }, 136 passphrase: 'passphrase' 137 } 138 139 var testExpect = { 140 hasError: true, 141 errorMsg: "address: invalid address", 142 143 } 144 145 testSendTransactionWithPassphrase(testInput, testExpect, done) 146 }); 147 148 it('4. empty `from`', done => { 149 var testInput = { 150 transaction: { 151 from: "", 152 to: toAddress, 153 value: "123", 154 nonce: "10000", 155 gas_price: "1000000", 156 gas_limit: "1000000", 157 contract: {} 158 }, 159 passphrase: 'passphrase' 160 } 161 162 var testExpect = { 163 hasError: true, 164 errorMsg: "address: invalid address", 165 166 } 167 168 testSendTransactionWithPassphrase(testInput, testExpect, done) 169 }); 170 171 it('5. illegal `to`', done => { 172 var testInput = { 173 transaction: { 174 from: address, 175 to: "afdas", 176 value: "", 177 nonce: "10000", 178 gas_price: "1000000", 179 gas_limit: "1000000", 180 contract: {} 181 }, 182 passphrase: 'passphrase' 183 } 184 185 var testExpect = { 186 hasError: true, 187 errorMsg: "address: invalid address", 188 189 } 190 191 testSendTransactionWithPassphrase(testInput, testExpect, done) 192 }); 193 194 it('6. empty `to`', done => { 195 var testInput = { 196 transaction: { 197 from: address, 198 to: "", 199 value: "", 200 nonce: "10000", 201 gas_price: "1000000", 202 gas_limit: "1000000", 203 contract: {} 204 }, 205 passphrase: 'passphrase' 206 } 207 208 var testExpect = { 209 hasError: true, 210 errorMsg: "address: invalid address", 211 212 } 213 214 testSendTransactionWithPassphrase(testInput, testExpect, done) 215 }); 216 217 it('7. alpha `value', done => { 218 var testInput = { 219 transaction: { 220 from: address, 221 to: toAddress, 222 value: "23ljfasf", 223 nonce: "10000", 224 gas_price: "1000000", 225 gas_limit: "1000000", 226 contract: {} 227 }, 228 passphrase: "passphrase" 229 } 230 231 var testExpect = { 232 hasError: true, 233 errorMsg: "invalid value", 234 235 } 236 237 testSendTransactionWithPassphrase(testInput, testExpect, done) 238 }); 239 240 it('8. negative `value`', done => { 241 var testInput = { 242 transaction: { 243 from: address, 244 to: toAddress, 245 value: "-3242", 246 nonce: "10000", 247 gas_price: "1000000", 248 gas_limit: "1000000", 249 contract: {} 250 }, 251 passphrase: "passphrase" 252 } 253 254 var testExpect = { 255 hasError: true, 256 errorMsg: "invalid value", 257 258 } 259 260 testSendTransactionWithPassphrase(testInput, testExpect, done) 261 }); 262 263 it('9. empty `value`', done => { 264 var testInput = { 265 transaction: { 266 from: address, 267 to: toAddress, 268 value: "", 269 nonce: "10000", 270 gas_price: "1000000", 271 gas_limit: "1000000", 272 contract: {} 273 }, 274 passphrase: "passphrase" 275 } 276 277 var testExpect = { 278 hasError: true, 279 errorMsg: "invalid value", 280 281 } 282 283 testSendTransactionWithPassphrase(testInput, testExpect, done) 284 }); 285 286 it('10. alpha `nonce`', done => { 287 var testInput = { 288 transaction: { 289 from: address, 290 to: toAddress, 291 value: "123", 292 nonce: "abasdx", 293 gas_price: "1000000", 294 gas_limit: "1000000", 295 contract: {} 296 }, 297 passphrase: "passphrase" 298 } 299 300 var testExpect = { 301 hasError: true, 302 errorMsg: "transaction's nonce is invalid, should bigger than the from's nonce", 303 304 } 305 306 testSendTransactionWithPassphrase(testInput, testExpect, done) 307 }); 308 309 it('11. empty `nonce`', done => { 310 var testInput = { 311 transaction: { 312 from: address, 313 to: toAddress, 314 value: "123", 315 nonce: "", 316 gas_price: "1000000", 317 gas_limit: "1000000", 318 contract: {} 319 }, 320 passphrase: "passphrase" 321 } 322 323 var testExpect = { 324 hasError: true, 325 cannotExecuteError: 'Error:' 326 } 327 328 testSendTransactionWithPassphrase(testInput, testExpect, done) 329 }); 330 331 it('12. negative `nonce`', done => { 332 var testInput = { 333 transaction: { 334 from: address, 335 to: toAddress, 336 value: "123", 337 nonce: "-10000", 338 gas_price: "1000000", 339 gas_limit: "1000000", 340 contract: {} 341 }, 342 passphrase: "passphrase" 343 } 344 345 var testExpect = { 346 hasError: false, 347 cannotExecuteError: '' 348 } 349 350 testSendTransactionWithPassphrase(testInput, testExpect, done) 351 }); 352 353 it('13. not bigger than from `nonce`', done => { 354 var testInput = { 355 transaction: { 356 from: address, 357 to: toAddress, 358 value: "123", 359 nonce: "0", 360 gas_price: "1000000", 361 gas_limit: "1000000", 362 contract: {} 363 }, 364 passphrase: "passphrase" 365 } 366 367 var testExpect = { 368 hasError: true, 369 370 errorMsg: "transaction's nonce is invalid, should bigger than the from's nonce", 371 372 } 373 374 testSendTransactionWithPassphrase(testInput, testExpect, done) 375 }); 376 377 it('14. alpha `gas_price`', done => { 378 var testInput = { 379 transaction: { 380 from: address, 381 to: toAddress, 382 value: "123", 383 nonce: "10000", 384 gas_price: "fasf", 385 gas_limit: "1000000", 386 contract: {} 387 }, 388 passphrase: "passphrase" 389 } 390 391 var testExpect = { 392 hasError: true, 393 errorMsg: "invalid gasPrice", 394 395 } 396 testSendTransactionWithPassphrase(testInput, testExpect, done) 397 }); 398 399 it('15. negative `gas_price`', done => { 400 var testInput = { 401 transaction: { 402 from: address, 403 to: toAddress, 404 value: "123", 405 nonce: 10000, 406 gas_price: "-10000", 407 gas_limit: "1000000", 408 contract: {} 409 }, 410 passphrase: "passphrase" 411 } 412 413 var testExpect = { 414 hasError: true, 415 errorMsg: "invalid gasPrice", 416 417 } 418 testSendTransactionWithPassphrase(testInput, testExpect, done) 419 }); 420 421 it('16. empty `gas_price`', done => { 422 var testInput = { 423 transaction: { 424 from: address, 425 to: toAddress, 426 value: "123", 427 nonce: "", 428 gas_price: "", 429 gas_limit: "1000000", 430 contract: {} 431 }, 432 passphrase: "passphrase" 433 } 434 435 var testExpect = { 436 hasError: true, 437 errorMsg: "", 438 cannotExecuteError: 'Error:' 439 440 } 441 testSendTransactionWithPassphrase(testInput, testExpect, done) 442 }); 443 444 it('17. alpha `gas_limit`', done => { 445 var testInput = { 446 transaction: { 447 from: address, 448 to: toAddress, 449 value: "1233455234", 450 nonce: "10000", 451 gas_price: "10000", 452 gas_limit: "afsdkjkjkkjhf", 453 contract: {} 454 }, 455 passphrase: "passphrase" 456 } 457 458 var testExpect = { 459 hasError: true, 460 errorMsg: "invalid gasLimit", 461 462 } 463 testSendTransactionWithPassphrase(testInput, testExpect, done) 464 }); 465 466 // it('16. alpha `gas_limit` & sufficient `gas_price`', done => { 467 // var testInput = { 468 // transaction: { 469 // from: address, 470 // to: toAddress, 471 // value: "123", 472 // nonce: "10000", 473 // gas_price: "1000000", 474 // gas_limit: "afsdkjkjkkjhf", 475 // contract: {} 476 // }, 477 // passphrase: "passphrase" 478 // } 479 480 // var testExpect = { 481 // hasError: true, 482 483 // } 484 // testSendTransactionWithPassphrase(testInput, testExpect, done) 485 // }); 486 487 it('18. negative number `gas_limit`', done => { 488 var testInput = { 489 transaction: { 490 from: address, 491 to: toAddress, 492 value: "123", 493 nonce: 10000, 494 gas_price: "10000", 495 gas_limit: "-1000000", 496 contract: {} 497 }, 498 passphrase: "passphrase" 499 } 500 501 var testExpect = { 502 hasError: true, 503 errorMsg: "invalid gasLimit", 504 505 } 506 testSendTransactionWithPassphrase(testInput, testExpect, done) 507 }); 508 509 it('19. empty `gas_limit`', done => { 510 var testInput = { 511 transaction: { 512 from: address, 513 to: toAddress, 514 value: "123", 515 nonce: "", 516 gas_price: "134241", 517 gas_limit: "", 518 contract: {} 519 }, 520 passphrase: "passphrase" 521 } 522 523 var testExpect = { 524 hasError: true, 525 errorMsg: "", 526 cannotExecuteError: 'Error:' 527 528 } 529 testSendTransactionWithPassphrase(testInput, testExpect, done) 530 }); 531 532 /* it('20. normal `contract`', done => { 533 var testInput = { 534 transaction: { 535 from: address, 536 to: toAddress, // contract 537 value: "123", 538 nonce: "10000", 539 gas_price: "1000000", 540 gas_limit: "1000000", 541 contract: { 542 "function": "save", 543 } 544 }, 545 passphrase: "passphrase" 546 } 547 548 var testExpect = { 549 hasError: true, 550 errorMsg: "cannot found account in storage", 551 552 } 553 554 testSendTransactionWithPassphrase(testInput, testExpect, done) 555 }); 556 557 it('21. empty `contract`', done => { 558 var testInput = { 559 transaction: { 560 from: address, 561 to: toAddress, 562 value: "123", 563 nonce: "10000", 564 gas_price: "1000000", 565 gas_limit: "1000000", 566 contract: {} 567 }, 568 passphrase: "passphrase" 569 } 570 571 var testExpect = { 572 hasError: true, 573 errorMsg: "duplicated transaction", 574 575 } 576 577 testSendTransactionWithPassphrase(testInput, testExpect, done) 578 }); */ 579 580 it('20. wrong `passphrase`', done => { 581 var testInput = { 582 transaction: { 583 from: address, 584 to: toAddress, 585 value: "123", 586 nonce: "10000", 587 gas_price: "1000000", 588 gas_limit: "1000000", 589 contract: {} 590 }, 591 passphrase: "wrongpass" 592 } 593 594 var testExpect = { 595 hasError: true, 596 errorMsg: "could not decrypt key with given passphrase", 597 598 } 599 600 testSendTransactionWithPassphrase(testInput, testExpect, done) 601 }); 602 603 it('21. empty `passphrase`', done => { 604 var testInput = { 605 transaction: { 606 from: address, 607 to: toAddress, 608 value: "123", 609 nonce: "10000", 610 gas_price: "1000000", 611 gas_limit: "1000000", 612 contract: {} 613 }, 614 passphrase: "" 615 } 616 617 var testExpect = { 618 hasError: true, 619 errorMsg: "passphrase is invalid", 620 621 } 622 623 testSendTransactionWithPassphrase(testInput, testExpect, done) 624 }); 625 });