git ssb

0+

wanderer🌟 / js-primea-objects



Tree: 19ce496560f9ea1fb3b35eefab4afbe9b8d581eb

Files: 19ce496560f9ea1fb3b35eefab4afbe9b8d581eb / tests / index.js

1533 bytesRaw
1const Buffer = require('safe-buffer').Buffer
2const tape = require('tape')
3const cbor = require('borc')
4const objects = require('../')
5
6tape('system objects', t => {
7
8 t.equals(objects.getType(), 'invalid')
9 t.equals(objects.getType(true), 'invalid')
10 const msg = new objects.Message({
11 ticks: 100
12 })
13
14 t.equals(objects.getType(msg), 'message')
15 t.equals(msg.ticks, 100)
16 msg.ticks = 10
17 t.equals(msg.ticks, 10)
18
19 const id = new objects.ID(Buffer.from([0x1]))
20 const enid = cbor.encode(id)
21 const rid = objects.decoder.decodeFirst(enid)
22 t.equals(rid.toString(), '01')
23 t.equals(objects.getType(id), 'id')
24
25 const modRef = new objects.ModuleRef({'name': ['i32']}, id)
26 const enmod = cbor.encode(modRef)
27 const rmodRef = objects.decoder.decodeFirst(enmod)
28 t.equals(objects.getType(modRef), 'mod')
29 t.deepEquals(modRef, rmodRef)
30
31 const funcRef = rmodRef.getFuncRef('name')
32 funcRef.gas = 1000
33 const funcRef2 = funcRef.copy()
34 funcRef2.gas = 500
35 t.equals(funcRef.gas, 1000, 'should have correct gas amount')
36 const enFuncRef = cbor.encode(funcRef)
37 const rFuncRef = objects.decoder.decodeFirst(enFuncRef)
38 t.deepEquals(funcRef, rFuncRef)
39 t.equals(objects.getType(rFuncRef), 'func')
40
41 const link = new cbor.Tagged(42, 'data')
42 const enLink = cbor.encode(link)
43 const rLink = objects.decoder.decodeFirst(enLink)
44 t.deepEquals(rLink, {'/': 'data'})
45 t.equals(objects.getType(rLink), 'link')
46
47 t.equals(objects.getType([]), 'elem')
48 t.equals(objects.getType(Buffer.from([])), 'data')
49
50 t.end()
51})
52

Built with git-ssb-web