1 | chaiAsPromised = require 'chai-as-promised'
|
2 | chai = require 'chai'
|
3 | chai.use chaiAsPromised
|
4 | expect = chai.expect
|
5 |
|
6 | Custodian = require '../lib/custodian'
|
7 | Envelope = require 'ecc-envelope'
|
8 |
|
9 | _ = require 'lodash'
|
10 | bs = require 'bs58check'
|
11 | ecc = require 'ecc-tools'
|
12 |
|
13 | describe 'Custodian', ->
|
14 | before ->
|
15 | @custodian = Custodian()
|
16 | @barHash = bs.decode('aYSAd13fa7mzsguAoaXnecLfpTDKziwQ4BN2r3QLdi4QcLVZZ')
|
17 |
|
18 | describe 'data', ->
|
19 | it 'should allow me to put a value and get a the hash', ->
|
20 | result = @custodian.data.put('bar')
|
21 | expect(result).to.eventually.deep.equal(@barHash)
|
22 |
|
23 | it 'should allow me to get a value from the hash', ->
|
24 | result = @custodian.data.get(@barHash)
|
25 | expect(result).to.eventually.equal('bar')
|
26 |
|
27 | describe 'document', ->
|
28 | before ->
|
29 | @privateKey = ecc.privateKey()
|
30 | @publicKey = ecc.publicKey(@privateKey, true)
|
31 | @envelope = Envelope(send: {hello: 'world'}, from: @privateKey)
|
32 |
|
33 | it 'should allow me to put a value and get a the key', ->
|
34 | result = @custodian.document.put(@envelope.encode())
|
35 | expect(result).to.eventually.deep.equal(@publicKey)
|
36 |
|
37 | it 'should allow me to get a value from the key', ->
|
38 | result = @custodian.document.get(@publicKey)
|
39 | @envelope.encode().then (envelope) ->
|
40 | expect(result).to.eventually.deep.equal(envelope)
|