Skip to content

Commit

Permalink
rename ABF to TypedEncoding
Browse files Browse the repository at this point in the history
  • Loading branch information
bchamagne committed Oct 17, 2023
1 parent f98e67a commit 24d9ecf
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 48 deletions.
4 changes: 2 additions & 2 deletions src/transaction_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
toByteArray,
uint8ArrayToHex
} from "./utils.js";
import ABF from "./abf.js"
import TE from "./typed_encoding.js"
import { deriveAddress, deriveKeyPair, sign } from "./crypto.js";

const VERSION = 3
Expand Down Expand Up @@ -360,7 +360,7 @@ export default class TransactionBuilder {
// address
address)
} else {
const serializedArgs = args.map((arg) => ABF.serialize(arg))
const serializedArgs = args.map((arg) => TE.serialize(arg))

return concatUint8Arrays(
// 1 = named action
Expand Down
4 changes: 1 addition & 3 deletions src/abf.ts → src/typed_encoding.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ABF stands for Archethic Binary Format

import {
concatUint8Arrays,
toBigInt,
Expand Down Expand Up @@ -27,7 +25,7 @@ function serialize(data: any): Uint8Array {
data = sortObjectKeysASC(data)

return concatUint8Arrays(
// abf version 1
// version 1
Uint8Array.from([1]),
do_serialize_v1(data)
)
Expand Down
40 changes: 0 additions & 40 deletions tests/abf.test.ts

This file was deleted.

6 changes: 3 additions & 3 deletions tests/transaction_builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
uint8ArrayToHex,
} from "../src/utils";
import { Curve } from "../src/types";
import ABF from "../src/abf";
import TE from "../src/typed_encoding";

const VERSION = 3

Expand Down Expand Up @@ -401,7 +401,7 @@ describe("Transaction builder", () => {
// args size
Uint8Array.from([1]),
// args value
ABF.serialize("Ms. Smith")
TE.serialize("Ms. Smith")
);
expect(payload).toEqual(expected_binary);

Expand Down Expand Up @@ -460,7 +460,7 @@ describe("Transaction builder", () => {
// args size
Uint8Array.from([1]),
// args value
ABF.serialize({ "lng": 2, "lat": 1 })
TE.serialize({ "lng": 2, "lat": 1 })
);
expect(payload).toEqual(expected_binary);

Expand Down
40 changes: 40 additions & 0 deletions tests/typed_encoding.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import TE from "../src/typed_encoding"

describe("TE", () => {
it("should serialize/deserialize a null", () => {
expect(TE.deserialize(TE.serialize(null))).toBeNull()
})
it("should serialize/deserialize a bool", () => {
expect(TE.deserialize(TE.serialize(true))).toBe(true)
expect(TE.deserialize(TE.serialize(false))).toBe(false)
})
it("should serialize/deserialize an integer", () => {
expect(TE.deserialize(TE.serialize(0))).toBe(0)
expect(TE.deserialize(TE.serialize(1))).toBe(1)
expect(TE.deserialize(TE.serialize(2 ** 40))).toBe(2 ** 40)
})
it("should serialize/deserialize a float", () => {
expect(TE.deserialize(TE.serialize(1.00000001))).toBe(1.00000001)
expect(TE.deserialize(TE.serialize(1.99999999))).toBe(1.99999999)
})
it("should serialize/deserialize a str", () => {
expect(TE.deserialize(TE.serialize("hello"))).toBe("hello")
expect(TE.deserialize(TE.serialize("world"))).toBe("world")
})

it("should serialize/deserialize a list", () => {
expect(TE.deserialize(TE.serialize([]))).toStrictEqual([])
expect(TE.deserialize(TE.serialize([1, 2, 3]))).toStrictEqual([1, 2, 3])
expect(TE.deserialize(TE.serialize(["1", true, 14]))).toStrictEqual(["1", true, 14])
})
it("should serialize/deserialize an object", () => {
expect(TE.deserialize(TE.serialize({}))).toStrictEqual({})
expect(TE.deserialize(TE.serialize({ a: 1, foo: "bar" }))).toStrictEqual({ a: 1, foo: "bar" })
})
it("should serialize/deserialize a map", () => {
let map = new Map()
map.set({ oooo: "iii" }, 44)
map.set(["aaaaa", "bbbbb"], 45)
expect(TE.deserialize(TE.serialize(map))).toStrictEqual(map)
})
})

0 comments on commit 24d9ecf

Please sign in to comment.