Skip to content

Commit 3c7f3e4

Browse files
Merge pull request #61 from LimeChain/fix/hex-encoding
Fix bug hex conversion, import interfaces
2 parents 874d232 + 6d639d0 commit 3c7f3e4

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

assembly/Arrays/ByteArray.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class ByteArray extends AbstractArray<Byte, u8> {
2727
public toHexString (): string {
2828
let result = "0x";
2929
for (let i = 0; i < super.values.length; i++) {
30-
const str = super.values[i].toString();
30+
const str = super.values[i].toString(16);
3131
if (str.length == 1) {
3232
result += "0";
3333
}

assembly/__tests__/ScaleString.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ describe("String", () => {
4747
expect<string>(scaleString1.toString()).toStrictEqual("da");
4848
});
4949

50+
it("should encode to hex", () => {
51+
const scaleString = new ScaleString("as-scale-codec");
52+
expect<string>(scaleString.toHexString()).toStrictEqual("0x61732d7363616c652d636f646563");
53+
const scaleString1 = new ScaleString("The 1963 Impala featured rectilinear styling with an engine-turned aluminum rear taillight panel surrounded by a chrome border on SS models.");
54+
expect<string>(scaleString1.toHexString()).toStrictEqual("0x546865203139363320496d70616c612066656174757265642072656374696c696e656172207374796c696e67207769746820616e20656e67696e652d7475726e656420616c756d696e756d2072656172207461696c6c696768742070616e656c20737572726f756e6465642062792061206368726f6d6520626f72646572206f6e205353206d6f64656c732e");
55+
const scaleString2 = new ScaleString("A set of words that is complete in itself, typically containing a subject and predicate");
56+
expect<string>(scaleString2.toHexString()).toStrictEqual("0x4120736574206f6620776f726473207468617420697320636f6d706c65746520696e20697473656c662c207479706963616c6c7920636f6e7461696e696e672061207375626a65637420616e6420707265646963617465");
57+
})
58+
5059
itThrows("should throw on incorrect encoding", () => {
5160
ScaleString.fromU8a([0x04]); // Encoded length = 1, actual data length = 0
5261
});

assembly/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export * from "./Byte";
44
export * from "./BytesReader";
55
export * from "./Hash";
66
export * from "./Int";
7-
export * from "./interfaces/Codec";
7+
export * from "./interfaces";
88
export * from "./ScaleMap";
99
export * from "./ScaleString";
1010
export * from "./UInt";

assembly/interfaces/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './Codec';
2+
export * from './DecodedData';
3+
export * from './UnwrappableCodec';

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "as-scale-codec",
3-
"version": "0.1.1",
3+
"version": "0.2.1",
44
"description": "AssemblyScript implementation of the SCALE codec used in the Parity Substrate framework",
55
"main": "./assembly/index.ts",
66
"contributors": [

0 commit comments

Comments
 (0)