Skip to content

Commit

Permalink
Make tests compatible with tape
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Nov 30, 2024
1 parent 244956e commit 96f4392
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/ChainObjectEncoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const microBlockData = new Uint8Array([
])

test('Encode MicroBlock Object', t => {
t.plan(1)
// console.dir(encoder.encode(microBlock), {maxArrayLength: null})
t.deepEqual(
encoder.encode(microBlock),
Expand All @@ -83,6 +84,7 @@ test('Encode MicroBlock Object', t => {
})

test('Decode MicroBlock Object', t => {
t.plan(1)
t.deepEqual(
encoder.decode('micro_block', microBlockData),
microBlock
Expand Down Expand Up @@ -131,13 +133,15 @@ const keyBlockData = new Uint8Array([
])

test('Encode KeyBlock Object', t => {
t.plan(1)
t.deepEqual(
encoder.encode(keyBlock),
keyBlockData
)
})

test('Decode KeyBlock Object', t => {
t.plan(1)
t.deepEqual(
encoder.decode('key_block', keyBlockData),
keyBlock
Expand Down
10 changes: 10 additions & 0 deletions tests/ChainObjectSerializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import FieldsEncoder from '../src/ChainObjects/FieldsEncoder.js'
const serializer = new ChainObjectSerializer(new FieldsEncoder(new FieldEncoder()))

test('Serialize Account', t => {
t.plan(2)

t.deepEqual(
serializer.serialize(new ChainObject('account', {balance: 0n, nonce: 0n})),
new Uint8Array([196, 10, 1, 0, 0])
Expand All @@ -19,6 +21,8 @@ test('Serialize Account', t => {
})

test('Deserialize Account', t => {
t.plan(2)

t.deepEqual(
serializer.deserialize(new Uint8Array([196, 10, 1, 0, 0])),
new ChainObject('account', {balance: 0n, nonce: 0n}),
Expand All @@ -31,6 +35,7 @@ test('Deserialize Account', t => {
})

test('Serialize SpendTx', t => {
t.plan(1)
t.deepEqual(
serializer.serialize(new ChainObject('spend_tx', {
sender: 'ak_11111111111111111111111111111118qjnEr',
Expand All @@ -50,6 +55,7 @@ test('Serialize SpendTx', t => {
})

test('Deserialize SpendTx', t => {
t.plan(1)
t.deepEqual(
serializer.deserialize(new Uint8Array([
248, 75, 12, 1, 161, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down Expand Up @@ -110,13 +116,15 @@ const signedTxData = new Uint8Array([
])

test('Serialize SignedTx', t => {
t.plan(1)
t.deepEqual(
serializer.serialize(signedTx),
signedTxData
)
})

test('Deserialize SignedTx', t => {
t.plan(1)
t.deepEqual(
serializer.deserialize(signedTxData),
signedTx
Expand Down Expand Up @@ -165,13 +173,15 @@ const lightMicroBlockData = new Uint8Array([
])

test('Serialize Light MicroBlock', t => {
t.plan(1)
t.deepEqual(
serializer.serialize(lightMicroBlock),
lightMicroBlockData
)
})

test('Deserialize Light MicroBlock', t => {
t.plan(1)
t.deepEqual(
serializer.deserialize(lightMicroBlockData),
lightMicroBlock
Expand Down
27 changes: 26 additions & 1 deletion tests/ContractEncoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ test('Decode contract with Chain.create', t => {

const contract = encoder.decode('cb_+NBGA6D+x/gUE1YYLmvMJDIzJK2ZFJyOM5sXubwJy+9TVt/ib8C4n7iE/kTWRB8ANwA3ABoOgj8BAz/+m66dXgA3AQdHAgwBAAwDAAwDNwEHDAOPbxX4U0YDoJg7mklGIIWH49uiZBksC7yUEVO88y4D7lTd8+T4TMK2wKOS/kTWRB8ANwEHNwAaBoIAAQM/jC8BEUTWRB8RaW5pdIIvAIk4LjAuMC1yYzEAowAAlS8CEUTWRB8RaW5pdBGbrp1eDW5ld4IvAIk4LjAuMC1yYzEAaSb5ng==')

t.like(contract.bytecode.functions[1].instructions[0][3], {
t.deepEqual(contract.bytecode.functions[1].instructions[0][3], {
mnemonic: 'PUSH',
args: [{
mod: 'immediate',
Expand All @@ -69,6 +69,31 @@ test('Decode contract with Chain.create', t => {
vsn: 3n,
sourceHash: '983b9a4946208587e3dba264192c0bbc941153bcf32e03ee54ddf3e4f84cc2b6',
aevmTypeInfo: [],
bytecode: {
functions: [{
id: '44d6441f',
name: 'init',
attributes: [],
args: { name: 'tuple', valueTypes: [{name: 'int'}]},
returnType: { name: 'tuple', valueTypes: [] },
instructions: [
[
{
mnemonic: 'STORE',
args: [{mod: 'var', arg: -1n}, {mod: 'arg', arg: 0n}]
},
{
mnemonic: 'RETURNR',
args: [{mod: 'immediate', arg: []}]
},
]
]
}],
symbols: {
'44d6441f': 'init'
},
annotations: new Map()
},
compilerVersion: '8.0.0-rc1',
payable: false
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Decoder.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from 'safe-buffer'
import test from './test.js'
import Encoder from '../src/Encoder.js'
import hexStringToByteArray from '../src/utils/hexStringToByteArray.js'
Expand Down Expand Up @@ -589,6 +590,7 @@ test('Decode BLS12_381.g1', t => {
})

test('Decode generic contract byte array', t => {
t.plan(1)
// just make sure the method exists
t.is(encoder.decodeContractByteArray('cb_/8CwV/U='), true)
})
Expand Down
2 changes: 2 additions & 0 deletions tests/Encoder.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from 'safe-buffer'
import test from './test.js'
import Encoder from '../src/Encoder.js'
import aci from '../build/contracts/Test.json' with { type: 'json' }
Expand Down Expand Up @@ -221,6 +222,7 @@ test('Encode map arguments', t => {
})

test('Encode map arguments with sorted keys', t => {
t.plan(2)
const encoded = encoder.encode(CONTRACT, 'test_string_map', [[["fo", "a"], ["s", "a"]]])
t.is(encoded, 'cb_KxFFPju5Gy8CBXMFYQlmbwVhMOIQaw==', 'test_string_map({["fo"] = "a", ["s"] = "a"})')

Expand Down

0 comments on commit 96f4392

Please sign in to comment.