UNPKG

4.08 kBJavaScriptView Raw
1let ScryptaCore = require('../src/index.js')
2let scrypta = new ScryptaCore
3var assert = require('assert')
4const password = '123456'
5
6describe('Addresses', async function() {
7 it('Should return all nodes', async function(){
8 let nodes = await scrypta.returnNodes()
9 assert.equal(16, nodes.length);
10 })
11 it('Address should be length 34 bytes', async function(){
12 let address = await scrypta.createAddress(password, true)
13 assert.equal(34, address.pub.length);
14 })
15 it('PubKey should be length 66 bytes', async function(){
16 let address = await scrypta.createAddress(password, true)
17 assert.equal(66, address.key.length);
18 })
19 it('PrivKey should be length 52 bytes', async function(){
20 let address = await scrypta.createAddress(password, true)
21 assert.equal(52, address.prv.length);
22 })
23 it('Wallet store shuold be decryptable and address should be the same', async function(){
24 let address = await scrypta.createAddress(password, true)
25 let readed = await scrypta.readKey(password, address.walletstore)
26 assert.equal(readed.key, address.key);
27 })
28 it('Should import a private key', async function(){
29 let address = await scrypta.createAddress(password, true)
30 let key = await scrypta.importPrivateKey(address.prv, password)
31 assert.equal(key.prv, address.prv);
32 })
33 it('Should return all identities', async function(){
34 let identities = await scrypta.returnIdentities()
35 assert.notEqual(0, identities.count);
36 })
37 it('Address can send a transaction', async function(){
38 this.timeout(35000)
39 let prv = 'SqKfYCBLjWx3NobRBTdeHN75HXn9f9wgi2po1QkwLvwHxCVHM3Qw'
40 let pub = 'LY6BHLvjNbHCQxnpGgt6BvXhXjfX6Nk1X2'
41 let to = 'LKXyszE4EQGRZZKuua5qdyu7PuGuowQHX4'
42 let amount = 0.001
43 let password = 'password'
44 await scrypta.importPrivateKey(prv, password)
45 let tx = await scrypta.send(pub, password, to, amount)
46 console.log(tx)
47 assert.equal(64, tx.length);
48 })
49 it('Should create RSA keys for identity', async function(){
50 this.timeout(15000)
51 let address = await scrypta.createAddress(password, true)
52 await scrypta.createRSAKeys(address.pub, password)
53 let identity = await scrypta.returnIdentity(address.pub)
54 assert.notEqual(undefined, identity.rsa);
55 })
56});
57
58describe('Idanodes', async function() {
59 it('Should GET first available IdaNode', function(){
60 this.timeout(35000)
61 return new Promise(async response => {
62 let getinfo = await scrypta.get('/wallet/getinfo', 'https://idanodejs09.scryptachain.org')
63 if(getinfo !== false){
64 response(getinfo)
65 }
66 })
67 })
68
69 it('Should POST first available IdaNode', async function(){
70 this.timeout(35000)
71 let Bob = await scrypta.createAddress(password, true)
72 let Alice = await scrypta.createAddress(password, true)
73 let trustlink = await scrypta.post('/trustlink/init', { addresses: Bob.key + ',' + Alice.key, airdrop: false})
74 assert.equal(34, trustlink.data.address.length);
75 })
76});
77
78describe('Planum', async function() {
79 it('Should return a list of unspent', async function(){
80 this.timeout(30000)
81 scrypta.usePlanum('6ShzCp8oXAqVSZdrkNMSj13ghobwZZRzGm')
82 let unspent = await scrypta.listPlanumUnspent('LchzGX6vqmanceCzNUMTk5cmnt1p6knGgT')
83 assert.equal(1, unspent.length);
84 })
85})
86
87describe('P2P Network', async function() {
88 it('Should connect to p2p network and send a message', function(){
89 this.timeout(15000)
90 return new Promise(async response => {
91 let address = await scrypta.createAddress(password, true)
92 scrypta.connectP2P(function(received){
93 response(received)
94 })
95 setInterval(function(){
96 scrypta.broadcast(address.walletstore, password, 'message', 'Now are '+ new Date() +'!')
97 },3500)
98 })
99 })
100})