|
| 1 | +import { test } from 'tape-promise/tape'; |
| 2 | +import { makeRegistrar } from '../../../../more/registrar/registrar'; |
| 3 | + |
| 4 | +test('Registrar creation', async t => { |
| 5 | + try { |
| 6 | + const registrarService = makeRegistrar('testnet'); |
| 7 | + const obj1 = {}; |
| 8 | + const obj2 = {}; |
| 9 | + const id1 = registrarService.register('myname', obj1); |
| 10 | + t.assert(id1.match(/^myname_\d{4,}$/), 'id1 is correct format') |
| 11 | + const id2 = registrarService.register('myname', obj2); |
| 12 | + t.assert(id2.match(/^myname_\d{4,}$/), 'id2 is correct format') |
| 13 | + t.isNot(id2, id1, 'ids for different objects are different'); |
| 14 | + const id1a = registrarService.register('myname', obj1); |
| 15 | + t.assert(id1a.match(/^myname_\d{4,}$/), 'id1a is correct format') |
| 16 | + t.isNot(id1a, id1, 'ids for same object are different'); |
| 17 | + const id1b = registrarService.register('othername', obj1); |
| 18 | + t.assert(id1b.match(/^othername_\d{4,}$/), 'id1b is correct format') |
| 19 | + const ret1 = registrarService.get(id1); |
| 20 | + t.equals(ret1, obj1, 'returned obj1 is equal'); |
| 21 | + const ret2 = registrarService.get(id2); |
| 22 | + t.equals(ret2, obj2, 'returned obj2 is equal'); |
| 23 | + const ret1a = registrarService.get(id1a); |
| 24 | + t.equals(ret1a, obj1, 'returned obj1a is equal'); |
| 25 | + const ret1b = registrarService.get(id1b); |
| 26 | + t.equals(ret1b, obj1, 'returned obj1b is equal'); |
| 27 | + } catch (e) { |
| 28 | + t.isNot(e, e, 'unexpected exception'); |
| 29 | + } finally { |
| 30 | + t.end(); |
| 31 | + } |
| 32 | +}); |
0 commit comments