diff --git a/.gitignore b/.gitignore index ef773b4c..8658485f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,11 +7,14 @@ yarn.lock .idea/ *.bak *.new +*.log +v8.json *.DS_store +isolate*.log .esm-cache .sessionStorage .localStorage /types/**/*.ts !/types/**/*.d.ts /gun.ts -/temp/ +/temp/ \ No newline at end of file diff --git a/Procfile b/Procfile index 875fe822..fe18f22b 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: node --optimize_for_size --gc_interval=100 examples/http.js +web: node examples/http.js \ No newline at end of file diff --git a/axe.js b/axe.js index 8e3b6d4c..8b8348a7 100644 --- a/axe.js +++ b/axe.js @@ -1,22 +1,17 @@ ;(function(){ - /* UNBUILD */ - var root; - if(typeof window !== "undefined"){ root = window } - if(typeof global !== "undefined"){ root = global } - root = root || {}; - var console = root.console || {log: function(){}}; - function USE(arg, req){ - return req? require(arg) : arg.slice? USE[R(arg)] : function(mod, path){ - arg(mod = {exports: {}}); - USE[R(path)] = mod.exports; - } - function R(p){ - return p.split('/').slice(-1).toString().replace('.js',''); - } - } - if(typeof module !== "undefined"){ var common = module } - /* UNBUILD */ + /* UNBUILD */ + function USE(arg, req){ + return req? require(arg) : arg.slice? USE[R(arg)] : function(mod, path){ + arg(mod = {exports: {}}); + USE[R(path)] = mod.exports; + } + function R(p){ + return p.split('/').slice(-1).toString().replace('.js',''); + } + } + if(typeof module !== "undefined"){ var MODULE = module } + /* UNBUILD */ ;USE(function(module){ if(typeof window !== "undefined"){ module.window = window } @@ -24,7 +19,7 @@ var AXE = tmp.AXE || function(){}; if(AXE.window = module.window){ AXE.window.AXE = AXE } - try{ if(typeof common !== "undefined"){ common.exports = AXE } }catch(e){} + try{ if(typeof MODULE !== "undefined"){ MODULE.exports = AXE } }catch(e){} module.exports = AXE; })(USE, './root'); @@ -32,6 +27,7 @@ var AXE = USE('./root'), Gun = (AXE.window||{}).Gun || USE('./gun', 1); (Gun.AXE = AXE).GUN = AXE.Gun = Gun; + var ST = 0; Gun.on('opt', function(at){ start(at); @@ -73,11 +69,12 @@ The mob threshold might be determined by other factors, like how much RAM or CPU stress we have. */ - opt.mob = opt.mob || Infinity; + opt.mob = opt.mob || 9876 || Infinity; var mesh = opt.mesh = opt.mesh || Gun.Mesh(at); console.log("AXE enabled."); function verify(dht, msg) { + var S = (+new Date); var puts = Object.keys(msg.put); var soul = puts[0]; /// TODO: verify all souls in puts. Copy the msg only with subscribed souls? var subs = dht(soul); @@ -93,17 +90,20 @@ if (opt.super) { dht(soul, tmp.join(',')); } + console.STAT && console.STAT(S, +new Date - S, 'axe verify'); } function route(get){ var tmp; if(!get){ return } if('string' != typeof (tmp = get['#'])){ return } return tmp; } + // TODO: AXE NEEDS TO BE CHECKED FOR NEW CODE SYSTEM!!!!!!!!!! var Rad = (Gun.window||{}).Radix || USE('./lib/radix', 1); at.opt.dht = Rad(); - at.on('in', function input(msg){ - var to = this.to, peer = (msg._||{}).via; + at.on('in', input); + function input(msg){ + var to = this.to, peer = (msg._||'').via; // warning! mesh.leap could be buggy! var dht = opt.dht; var routes = axe.routes || (axe.routes = {}); // USE RAD INSTEAD! TMP TESTING! var get = msg.get, hash, tmp; @@ -128,8 +128,8 @@ } }*/ } - if((tmp = msg['@']) && (tmp = at.dup.s[tmp]) && (tmp = tmp.it)){ - (tmp = (tmp._||{})).ack = (tmp.ack || 0) + 1; // count remote ACKs to GET. + if((tmp = msg['@']) && (tmp = at.dup.s[tmp])){ + tmp.ack = (tmp.ack || 0) + 1; // count remote ACKs to GET. } to.next(msg); @@ -144,7 +144,7 @@ }); }); } - }); + }; //try{console.log(req.connection.remoteAddress)}catch(e){}; mesh.hear['opt'] = function(msg, peer){ @@ -189,6 +189,7 @@ var peers = routes[hash]; function chat(peers, old){ // what about optimizing for directed peers? if(!peers){ return chat(opt.peers) } + var S = (+new Date); // STATS! var ids = Object.keys(peers); // TODO: BUG! THIS IS BAD PERFORMANCE!!!! var meta = (msg._||yes); clearTimeout(meta.lack); @@ -198,12 +199,13 @@ meta.turn = (meta.turn || 0) + 1; if((old && old[id]) || false === mesh.say(msg, peer)){ ++c } } + console.STAT && (ST = +new Date - S) > 9 && console.STAT(S, ST, 'axe chat'); //console.log("AXE:", Gun.obj.copy(msg), meta.turn, c, ids, opt.peers === peers); if(0 < c){ if(peers === opt.peers){ return } // prevent infinite lack loop. return meta.turn = 0, chat(opt.peers, peers) } - var hash = msg['##'], ack = meta.ack; + var hash = msg['##'], ack = meta.ack || at.dup.s[msg['#']]; meta.lack = setTimeout(function(){ if(ack && hash && hash === msg['##']){ return } if(meta.turn >= (axe.turns || 3)){ return } // variable for later! Also consider ACK based turn limit. @@ -215,6 +217,7 @@ } // TODO: PUTs need to only go to subs! if(msg.put){ + var S = (+new Date); // STATS! var routes = axe.routes || (axe.routes = {}); // USE RAD INSTEAD! TMP TESTING! var peers = {}; Gun.obj.map(msg.put, function(node, soul){ @@ -223,6 +226,7 @@ if(!to){ return } Gun.obj.to(to, peers); }); + console.STAT && (ST = +new Date - S) > 9 && console.STAT(S, ST, 'axe put'); mesh.say(msg, peers); return; } @@ -246,24 +250,6 @@ } }); }; - /*var connections = 0; // THIS HAS BEEN MOVED TO CORE NOW! - at.on('hi', function(opt) { - this.to.next(opt); - //console.log('AXE PEER [HI]', new Date(), opt); - connections++; - /// The first connection don't need to resubscribe the nodes. - if (connections === 1) { return; } - /// Resubscribe all nodes. - setTimeout(function() { - var souls = Object.keys(at.graph); - for (var i=0; i < souls.length; ++i) { - //at.gun.get(souls[i]).off(); - at.next[souls[i]].ack = 0; - at.gun.get(souls[i]).once(function(){}); - } - //location.reload(); - }, 500); - }, at);*/ } axe.up = {}; at.on('hi', function(peer){ @@ -273,12 +259,14 @@ }); at.on('bye', function(peer){ this.to.next(peer); if(peer.url){ delete axe.up[peer.id] } + var S = +new Date; Gun.obj.map(peer.routes, function(route, hash){ delete route[peer.id]; if(Gun.obj.empty(route)){ delete axe.routes[hash]; } }); + console.STAT && console.STAT(S, +new Date - S, 'axe bye'); }); // handle rebalancing a mob of peers: diff --git a/examples/basic/user.html b/examples/basic/user.html index 588898f9..2c96e64a 100644 --- a/examples/basic/user.html +++ b/examples/basic/user.html @@ -22,6 +22,7 @@ \ No newline at end of file diff --git a/examples/todo/index.html b/examples/todo/index.html index 6f941d38..3764edc4 100644 --- a/examples/todo/index.html +++ b/examples/todo/index.html @@ -113,13 +113,12 @@ - - - + diff --git a/test/ptsd/perf.js b/test/ptsd/perf.js index e871bd4e..e4eaf900 100644 --- a/test/ptsd/perf.js +++ b/test/ptsd/perf.js @@ -16,7 +16,6 @@ ******* START AT THE BOTTOM AND READ UP ******* */ window.i = 1; - window.localStorage = window.localStorage || {clear: function(){}}; if(!this.stool){ return } setTimeout(function(){ stool.run(); diff --git a/test/ptsd/radix.js b/test/ptsd/radix.js index 81a8227d..c0514b76 100644 --- a/test/ptsd/radix.js +++ b/test/ptsd/radix.js @@ -16,11 +16,140 @@ stool.run(); },1); stool.setup(window.setup = function(){ - window.BigText = Gun.text.random(1024, 'abcdef'); - window.MedText = Gun.text.random(200, 'abcdef'); - window.jsonText = JSON.stringify(window.BigText); - window.radText = Radisk.encode(window.BigText); + //window.BigText = Gun.text.random(1024, 'abcdef'); + //window.MedText = Gun.text.random(200, 'abcdef'); + //window.jsonText = JSON.stringify(window.BigText); + //window.radText = Radisk.encode(window.BigText); + + window.namez = ["Adalard","Adora","Aia","Albertina","Alfie","Allyn","Amabil","Ammamaria","Andy","Anselme","Ardeen","Armand","Ashelman","Aube","Averyl","Baker","Barger","Baten","Bee","Benia","Bernat","Bevers","Bittner","Bobbe","Bonny","Boyce","Breech","Brittaney","Bryn","Burkitt","Cadmann","Campagna","Carlee","Carver","Cavallaro","Chainey","Chaunce","Ching","Cianca","Claudina","Clyve","Colon","Cooke","Corrina","Crawley","Cullie","Dacy","Daniela","Daryn","Deedee","Denie","Devland","Dimitri","Dolphin","Dorinda","Dream","Dunham","Eachelle","Edina","Eisenstark","Elish","Elvis","Eng","Erland","Ethan","Evelyn","Fairman","Faus","Fenner","Fillander","Flip","Foskett","Fredette","Fullerton","Gamali","Gaspar","Gemina","Germana","Gilberto","Giuditta","Goer","Gotcher","Greenstein","Grosvenor","Guthrey","Haldane","Hankins","Harriette","Hayman","Heise","Hepsiba","Hewie","Hiroshi","Holtorf","Howlond","Hurless","Ieso","Ingold","Isidora","Jacoba","Janelle","Jaye","Jennee","Jillana","Johnson","Josy","Justinian","Kannan","Kast","Keeley","Kennett","Kho","Kiran","Knowles","Koser","Kroll","LaMori","Lanctot","Lasky","Laverna","Leff","Leonanie","Lewert","Lilybel","Lissak","Longerich","Lou","Ludeman","Lyman","Madai","Maia","Malvina","Marcy","Maris","Martens","Mathilda","Maye","McLain","Melamie","Meras","Micco","Millburn","Mittel","Montfort","Moth","Mutz","Nananne","Nazler","Nesta","Nicolina","Noellyn","Nuli","Ody","Olympie","Orlena","Other","Pain","Parry","Paynter","Pentheas","Pettifer","Phyllida","Plath","Posehn","Proulx","Quinlan","Raimes","Ras","Redmer","Renelle","Ricard","Rior","Rocky","Ron","Rosetta","Rubia","Ruttger","Salbu","Sandy","Saw","Scholz","Secor","September","Shanleigh","Shenan","Sholes","Sig","Sisely","Soble","Spanos","Stanwinn","Stevie","Stu","Suzanne","Tacy","Tanney","Tekla","Thackeray","Thomasin","Tilla","Tomas","Tracay","Tristis","Ty","Urana","Valdis","Vasta","Vezza","Vitoria","Wait","Warring","Weissmann","Whetstone","Williamson","Wittenburg","Wymore","Yoho","Zamir","Zimmermann"]; + window.radix = window.radix || Radix(); + window.arr = []; var i = 1000; while(--i){ arr.push(Math.random()) } + window.arrs = arr.slice(0).sort(); + window.ALLZ = window.ALLZ || {}; + window.namez.forEach(function(v,i){ ALLZ[v] = i }); }); + /* TEMPORARY COPY OF RADIX UNIT TESTS TO BOOST SPEED */ + /* THESE ARE PROBABLY STALE AND NEED TO BE COPIED FROM UNIT TESTS AGAIN */ + /*stool.add('map', function(){ + Gun.obj.map(ALLZ, function(v,i){ + v; + }); + }); + stool.add('for', function(){ + for(var k in ALLZ){ + ALLZ[k]; + } + }); + stool.add('for', function(){ + Object.keys(ALLZ).forEach(function(k){ + ALLZ[k]; + }) + }); + return;*/ + stool.add('1', function(){ + var rad = Radix(); + rad('asdf.pub', 'yum'); + rad('ablah', 'cool'); + rad('ab', {yes: 1}); + rad('node/circle.bob', 'awesome'); + + (JSON.stringify(rad('asdf.')) !== JSON.stringify({pub: {'': 'yum'}})) && bada; + (rad('nv/foo.bar') != undefined) && badb; + (JSON.stringify(rad('ab')) != JSON.stringify({yes: 1})) && badc + (JSON.stringify(rad()) != JSON.stringify({"a":{"sdf.pub":{"":"yum"},"b":{"lah":{"":"cool"},"":{"yes":1}}},"node/circle.bob":{"":"awesome"}})) && badd; + }); + stool.add('2', function(){ + var all = {}; + namez.forEach(function(v,i){ + v = v.toLowerCase(); + all[v] = v; + ALLZ[v] = i; + radix(v, i) + }); + (Gun.obj.empty(all) === true) && bad3; + Radix.map(radix, function(v,k){ + delete all[k]; + }); + (Gun.obj.empty(all) !== true) && bad4; + }); + stool.add('fast?', function(){ + ALLZ['rubia']; + }); + stool.add('fastest?', function(){ + namez.indexOf('Rubia'); + }); + stool.add('3', function(){ + var all = {}; + namez.forEach(function(v,i){ + v = v.toLowerCase(); + all[v] = v; + //rad(v, i) + }); + (Gun.obj.empty(all) === true) && bad5; + Radix.map(radix, function(v,k){ + delete all[k]; + }); + (Gun.obj.empty(all) !== true) && bad6; + }); + stool.add('4', function(){ + var all = {}, start = 'Warring'.toLowerCase(), end = 'Zamir'.toLowerCase(); + namez.forEach(function(v,i){ + v = v.toLowerCase(); + if(v < start){ return } + if(end < v){ return } + all[v] = v; + //rad(v, i) + }); + (Gun.obj.empty(all) === true) && bad7; + Radix.map(radix, function(v,k, a,b){ + //if(!all[k]){ throw "out of range!" } + delete all[k]; + }, {start: start, end: end}); + (Gun.obj.empty(all) !== true) && bad8; + }); + stool.add('5', function(){ + var all = {}, start = 'Warrinf'.toLowerCase(), end = 'Zamis'.toLowerCase(); + namez.forEach(function(v,i){ + v = v.toLowerCase(); + if(v < start){ return } + if(end < v){ return } + all[v] = v; + //rad(v, i) + }); + (Gun.obj.empty(all) === true) && bad9; + Radix.map(radix, function(v,k, a,b){ + //if(!all[k]){ throw "out of range!" } + delete all[k]; + }, {start: start, end: end}); + (Gun.obj.empty(all) !== true) && bad10; + }); + stool.add('reverse item', function(){ + Radix.map(radix, function(v,k, a,b){ + (k !== 'ieso') && badri; + (v !== 96) && badri2; + return true; + }, {reverse: 1, end: 'iesogon'}); + }); + stool.add('6', function(){ + var r = Radix(), tmp; + r('alice', 1);r('bob', 2);r('carl', 3);r('carlo',4); + r('dave', 5);r('zach',6);r('zachary',7); + var by = ['alice','bob','carl','carlo','dave','zach','zachary']; + Gun.obj.map(by, function(k,i){ + r(k,i); + }); + Radix.map(r, function(v,k, a,b){ + (by.pop() !== k) && bad11; + tmp = v; + }, {reverse: 1}); + (tmp !== 1) && bad12; + (by.length !== 0) && bad13; + Radix.map(r, function(v,k, a,b){ + tmp = v; + }); + (tmp !== 7) && bad14; + }); + return; stool.add('JSON encode string', function(){ JSON.stringify(window.BigText); }); diff --git a/test/rad/bench.js b/test/rad/bench.js new file mode 100644 index 00000000..86bb5353 --- /dev/null +++ b/test/rad/bench.js @@ -0,0 +1,101 @@ +var Gun = (typeof window !== "undefined")? window.Gun : require('../../../gun/gun'); + +var Radisk = (Gun.window && window.Radisk) || require('../../../gun/lib/radisk'); +Gun.TESTING = true; +try{localStorage.clear()}catch(e){} +try{indexedDB.deleteDatabase('radatatest');}catch(e){} +try{indexedDB.deleteDatabase('radata');}catch(e){} + +var opt = {localStorage: false}; +//opt.chunk = 1024; +opt.store = (Gun.window && window.RindexedDB(opt)) || require('../../../gun/lib/rfs')(opt) +var rad = Radisk(opt); +//var gun = Gun(opt); +var gun = Gun('http://localhost:8765/gun'); + +Gun.window && (wait.onchange = function(){ spam.wait = this.value }) +Gun.window && (burst.onchange = function(){ spam.burst = this.value }) +//setTimeout(spam, 1); +function spam(){ + //spam.max = 100000; spam.left = spam.max; spam.wait = 1; spam.burst = 250; spam.c = 0; spam.s = (+new Date); + //spam.max = 1000000; spam.left = spam.max; spam.wait = 0; spam.burst = 100; spam.c = 0; spam.s = (+new Date); + //spam.max = 300000; spam.left = spam.max; spam.wait = 1; spam.burst = 5; spam.c = 0; spam.s = (+new Date); + //spam.max = 100000; spam.left = spam.max; spam.wait = 0; spam.burst = 2; spam.c = 0; spam.s = (+new Date); + //spam.max = 100000; spam.left = spam.max; spam.wait = 20; spam.burst = 2; spam.c = 0; spam.s = (+new Date); + //spam.max = 100; spam.left = spam.max; spam.wait = 1; spam.burst = 1; spam.c = 0; spam.s = (+new Date); + spam.max = 100000; spam.left = spam.max; spam.wait = 100; spam.burst = 100; spam.c = 99; spam.s = (+new Date); + var S = +new Date, slow = 0; console.only.i = 1; + var to = setTimeout(function gap(){ + if(spam.c >= spam.max){ clearTimeout(to); return; } + setTimeout(gap, Math.random() * 100); + var b = spam.burst; + b = Math.ceil(Math.random() * b); + //console.log('spam', +new Date - S, spam.c); S = +new Date; + if(!b){ b = burst = 1 } + while(b--){ go(++spam.c) } + function go(i){ var d = 0, s = +new Date; + i = Math.random().toString(32).slice(2); + //console.log('go', spam.c, i); + //setTimeout(function(){ var ack = {err: 0, ok: 1}; + //loc.put(i, {test: i}, function(err, ok){ var ack = {err: err, ok: ok}; + //ind.put(i, {test: i}, function(err, ok){ var ack = {err: err, ok: ok}; + //rad(i, {test: i}, function(err, ok){ var ack = {err: err, ok: ok}; + var ref = gun.get(i).put({test: i}, function(ack){ + var t = (+new Date - s)/1000; if(1 < t){ ++slow; } + if(ack.err){ console.log(ack); } + if(d++){ return } + if(--spam.left){ return } + spam.end = (+new Date) - spam.s; + console.log('DONE!\n', spam.max, 'in', spam.end/1000, 'seconds\n', Math.round(spam.max / (spam.end/1000)), 'per second. Slow:' + slow); + Gun.window && (document.body.style.backgroundColor = 'lime'); + }); + } + },spam.wait); + setInterval(function(){ + if(spam.end === true){ return } + if(spam.end){ spam.end = true } + var t = (+new Date) - spam.s, tmp, sec; + var status = 'saved\n'+ (tmp = (spam.max - spam.left)) +' in '+ (sec = (t/1000)) +' seconds\n'+ Math.round(tmp / sec) +' per second'; + (Gun.window && (debugs.innerText = status)) || console.log(status.replace(/\n/ig,' ')); + }, 500); +} +!Gun.window && setTimeout(spam,1); + +;(function(){ +if(!Gun.window){ return } +;(function(){ +var f = 'index'; +indexedDB.deleteDatabase(f); +var o = indexedDB.open(f, 1), ind = {}, db; +o.onupgradeneeded = function(eve){ (eve.target.result).createObjectStore(f) } +o.onsuccess = function(){ db = o.result } +o.onerror = function(eve){ console.log(eve||1); } +ind.put = function(key, data, cb){ + if(!db){ setTimeout(function(){ ind.put(key, data, cb) },9); return } + var tx = db.transaction([f], 'readwrite'); + var obj = tx.objectStore(f); + var req = obj.put(data, ''+key); + req.onsuccess = obj.onsuccess = tx.onsuccess = function(){ cb(null, 1) } + req.onabort = obj.onabort = tx.onabort = function(eve){ cb(eve||2) } + req.onerror = obj.onerror = tx.onerror = function(eve){ cb(eve||3) } +} +ind.get = function(key, cb){ + if(!db){ setTimeout(function(){ ind.get(key, cb) },9); return } + var tx = db.transaction([f], 'readwrite'); + var obj = tx.objectStore(f); + var req = obj.get(''+key); + req.onsuccess = function(){ cb(null, req.result) } + req.onabort = function(eve){ cb(eve||4) } + req.onerror = function(eve){ cb(eve||5) } +} +window.ind = ind; +}()); + +;(function(){ +localStorage.clear(); +var ls = localStorage, loc = {}; +loc.put = function(key, data, cb){ ls[''+key] = data; cb(null, 1) } +loc.get = function(key, cb){ cb(null, ls[''+key]) } +window.loc = loc; +}()); +}()); \ No newline at end of file diff --git a/test/rad/browser.html b/test/rad/browser.html index d864fa0e..3821b567 100644 --- a/test/rad/browser.html +++ b/test/rad/browser.html @@ -16,87 +16,6 @@
- - - - + \ No newline at end of file diff --git a/test/rad/rad.js b/test/rad/rad.js index bc2f5f5f..28c91dba 100644 --- a/test/rad/rad.js +++ b/test/rad/rad.js @@ -45,6 +45,20 @@ var names = ["Adalard","Adora","Aia","Albertina","Alfie","Allyn","Amabil","Ammam describe('Radix', function(){ var radix = Radix(); + + it('unit', function(){ + var rad = Radix(); + rad('asdf.pub', 'yum'); + rad('ablah', 'cool'); + rad('ab', {yes: 1}); + rad('node/circle.bob', 'awesome'); + + expect(Gun.obj.copy(rad('asdf.'))).to.be.eql({pub: {'': 'yum'}}); + expect(rad('nv/foo.bar')).to.be(undefined); + expect(rad('ab')).to.eql({yes: 1}); + expect(Gun.obj.copy(rad())).to.be.eql({"a":{"sdf.pub":{"":"yum"},"b":{"lah":{"":"cool"},"":{"yes":1}}},"node/circle.bob":{"":"awesome"}}); + }); + it('radix write read', function(done){ var all = {}; names.forEach(function(v,i){ @@ -110,6 +124,16 @@ var names = ["Adalard","Adora","Aia","Albertina","Alfie","Allyn","Amabil","Ammam expect(Gun.obj.empty(all)).to.be.ok(); done(); }); + + it('radix reverse item', function(done){ + var opt = {reverse: 1, end: 'iesogon'}; + Radix.map(radix, function(v,k, a,b){ + expect(k).to.be('ieso'); + expect(v).to.be(96); + return true; + }, opt); + done(); + }); it('radix reverse', function(done){ var r = Radix(), tmp; @@ -240,6 +264,7 @@ var names = ["Adalard","Adora","Aia","Albertina","Alfie","Allyn","Amabil","Ammam if(v.indexOf(find) == 0){ all[v] = true } }); rad(find, function(err, data, info){ + expect(data).to.be.ok(); Radix.map(data, function(v,k){ delete all[find+k]; }); @@ -288,12 +313,22 @@ var names = ["Adalard","Adora","Aia","Albertina","Alfie","Allyn","Amabil","Ammam }) }); + it('read one', function(done){ + //gun.get('names').get({'.': {'*': find}, '%': 1000 * 100}).once().map().once(function(data, key){ + gun.get('names').get('stu').once(function(data, key){ + expect(data.name).to.be.ok(); + expect(data.age).to.be.ok(); + done(); + }); + }); + it('read contacts', function(done){ var all = {}, find = 'm', to; names.forEach(function(v){ v = v.toLowerCase(); if(v.indexOf(find) == 0){ all[v] = true } }); + //console.log("<<<<<<<<<"); gun.get('names').get({'.': {'*': find}, '%': 1000 * 100}).once().map().once(function(data, key){ expect(data.name).to.be.ok(); expect(data.age).to.be.ok(); @@ -304,6 +339,7 @@ var names = ["Adalard","Adora","Aia","Albertina","Alfie","Allyn","Amabil","Ammam done(); },100); }); + //console.log(">>>>>>>>>"); }); it('read contacts again', function(done){ diff --git a/test/radix.js b/test/radix.js index 38450c1e..7ec5f37e 100644 --- a/test/radix.js +++ b/test/radix.js @@ -3,7 +3,7 @@ var expect = global.expect = require("./expect"); var Radix = require('../lib/radix'); var _ = String.fromCharCode(29); -describe('Radix', function(){ +describe('Radix', function(){ // moved to ./rad/rad.js it('read', function(){ var rad = Radix(); rad('asdf.pub', 'yum'); diff --git a/test/sea/sea.js b/test/sea/sea.js index 1a166804..aca6fc60 100644 --- a/test/sea/sea.js +++ b/test/sea/sea.js @@ -197,20 +197,20 @@ describe('SEA', function(){ expect(dec.priv).to.be(okey.priv); expect(dec.epriv).to.be(okey.epriv); - var gun = Gun(), tmp = Gun.node.soul(old); + var gun = Gun({super: true}), tmp = Gun.node.soul(old); var graph = {}; graph[tmp] = old; var alias = await SEA.verify(old.alias, false); expect(alias).to.be('bob'); alias = Gun.state.ify({}, tmp, 1, Gun.val.rel.ify(tmp), tmp = '~@'+alias); graph[tmp] = alias; - gun.on('put', {$: gun, put: graph}); + gun.on('test', {$: gun, put: graph}); var use = gun.user(); use.auth('bob', 'test123', function(ack){ expect(ack.err).to.not.be.ok(); done(); }); - }())}) + }())}); it('legacy []', function(done){ (async function(){ var pw = 'test123'; @@ -218,14 +218,14 @@ describe('SEA', function(){ var old = JSON.parse(atob("eyJfIjp7IiMiOiJ+VThkS0dySFJhX01sMFZ1YlR5OUZBYTlQS1ZlYlh0eTFjS05zWWxnYjduNC5QeVd5cUVVb0ZpYVduUElOV0Nad0xBbzFobjN1MldPWTU3SzZHZnpsNjhVIiwiPiI6eyJwdWIiOjE1NDY5MDI1MDQ5NzksImFsaWFzIjoxNTQ2OTAyNTA0OTc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- var gun = Gun(), tmp = Gun.node.soul(old); + var gun = Gun({super: true}), tmp = Gun.node.soul(old); var graph = {}; graph[tmp] = old; var alias = SEA.opt.unpack(await SEA.verify(old.alias, false), 'alias', old); expect(alias).to.be('alice'); alias = Gun.state.ify({}, tmp, 1, Gun.val.rel.ify(tmp), tmp = '~@'+alias); graph[tmp] = alias; - gun.on('put', {$: gun, put: graph}); + gun.on('test', {$: gun, put: graph}); var use = gun.user(); use.auth('alice', 'test123', function(ack){ expect(ack.err).to.not.be.ok(); @@ -277,8 +277,30 @@ describe('SEA', function(){ }); describe('User', function(){ + var gun = Gun(), gtmp; + + it('test', function(done){ + var g = Gun(); + user = g.user(); + var gid; + SEA.pair(function(p){ + user.is = user._.sea = p; + gtmp = gid = 'test~'+p.pub; + g.get(gid).put({yo: 'hi'}, function(ack){ + var data = SEA.opt.parse(g._.graph[gid].yo); + expect(data[':']).to.be('hi'); + expect(data['~']).to.be.ok(); + g.get(gid).get('yo').once(function(r){ + expect(r).to.be('hi'); + user.leave(); + done(); + }) + }) + }) + }); + it('is instantiable', function(done){ - gun = Gun(); + user.leave(); user = gun.user(); done(); }) @@ -289,7 +311,7 @@ describe('SEA', function(){ expect(ack.err).to.not.be.ok(); done(); }) - }) + }); it('login users', function(done){ user.auth('carl', 'test123', function(ack){ @@ -312,6 +334,35 @@ describe('SEA', function(){ }); }) + it('save json', function(done){ + user.get('a').get('c').put(JSON.stringify({hello:'world'}), function(ack){ + expect(ack.err).to.not.be.ok(); + done(); + }); + }) + + it('read json', function(done){ + user.get('a').get('c').once(function(data){ + expect(data).to.be(JSON.stringify({hello:'world'})); + done(); + }); + }) + + it('save & read encrypt', function(done){ + SEA.encrypt('hi', user._.sea, function(data){ + var is = data.slice(); + user.get('a').get('d').put(data, function(ack){ + expect(ack.err).to.not.be.ok(); + setTimeout(function(){ + user.get('a').get('d').once(function(data){ + expect(data).to.be(is); + done(); + }); + }) + }); + }) + }) + it('refresh login', function(done){ this.timeout(9000); setTimeout(function(){ @@ -347,6 +398,7 @@ describe('SEA', function(){ var ref = user.get('who').get('all').set(msg); user.get('who').get('said').set(ref); user.get('who').get('said').map().once(function(data){ + //console.log("*****", data); expect(data.what).to.be.ok(); done(); }) @@ -356,6 +408,7 @@ describe('SEA', function(){ it('set user ref null override', function(done){ this.timeout(9000); var gun = Gun(); + //user.leave(); var user = gun.user(); var msg = {what: 'hello world'}; user.create('xavier', 'password');