-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
60 changed files
with
10,316 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Integration tests for the entire SDK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
SDK Base | ||
-------- | ||
|
||
Provides Constants and utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { normalizeAmount } from "../src/"; | ||
|
||
describe("Amount Tests", function () { | ||
const cases: [number | string, bigint, bigint][] = [ | ||
[1, 18n, BigInt(1 + "0".repeat(18))], | ||
[0, 18n, BigInt(0)], | ||
[1, 2n, BigInt(1 + "0".repeat(2))], | ||
[3.2, 2n, BigInt(320)], | ||
["1.4", 12n, BigInt(1400000000000)], | ||
["0.0001", 12n, BigInt(100000000)], | ||
["0", 2n, BigInt(0)], | ||
// should we throw on negative? | ||
[-3, 2n, BigInt(-300)], | ||
["-3", 2n, BigInt(-300)], | ||
]; | ||
|
||
const badCases: [number | string, bigint][] = [ | ||
["0.000001", 2n], | ||
["-0.000001", 2n], | ||
["3", -2n], | ||
]; | ||
|
||
it("should correctly normalize values", function () { | ||
for (const [amt, dec, expected] of cases) { | ||
const actual = normalizeAmount(amt, dec); | ||
expect(actual).toEqual(expected); | ||
} | ||
}); | ||
|
||
it("should correctly fail on unexpected values", function () { | ||
for (const [amt, dec] of badCases) { | ||
const actual = () => normalizeAmount(amt, dec); | ||
expect(actual).toThrow(); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { test, describe, expect } from "@jest/globals"; | ||
import { toUint8Array, hex, b64, b58 } from "../src/utils/encoding"; | ||
|
||
// A table of base64 encoded strings and their decoded string equivalents | ||
const base64Table = [ | ||
["", ""], | ||
["f", "Zg=="], | ||
["fo", "Zm8="], | ||
["foo", "Zm9v"], | ||
["foob", "Zm9vYg=="], | ||
["fooba", "Zm9vYmE="], | ||
["foobar", "Zm9vYmFy"] | ||
]; | ||
|
||
// A table of hex encoded strings and their decoded string equivalents | ||
const hexTable = [ | ||
["", ""], | ||
["f", "66"], | ||
["fo", "666f"], | ||
["foo", "666f6f"], | ||
["foob", "666f6f62"], | ||
["fooba", "666f6f6261"], | ||
["foobar", "666f6f626172"] | ||
]; | ||
|
||
// A table of base58 encoded strings and their decoded string equivalents | ||
const base58Table = [ | ||
["", ""], | ||
["f", "2m"], | ||
["fo", "8o8"], | ||
["foo", "bQbp"], | ||
["foob", "3csAg9"], | ||
["fooba", "CZJRhmz"], | ||
["foobar", "t1Zv2yaZ"] | ||
]; | ||
|
||
|
||
describe("codec Tests", function () { | ||
|
||
describe("base64", function () { | ||
test.each(base64Table)("encodes properly", function (plain, expected) { | ||
const actual = b64.encode(plain) | ||
expect(actual).toEqual(expected) | ||
}); | ||
|
||
test.each(base64Table)("decodes properly", function (expected, encoded) { | ||
const actual = b64.decode(encoded) | ||
expect(actual).toEqual(toUint8Array(expected)) | ||
}); | ||
}) | ||
|
||
describe("hex", function () { | ||
test.each(hexTable)("encodes properly", function (plain, expected) { | ||
const actual = hex.encode(plain) | ||
expect(actual).toEqual(expected) | ||
}); | ||
|
||
test.each(hexTable)("decodes properly", function (expected, encoded) { | ||
const actual = hex.decode(encoded) | ||
expect(actual).toEqual(toUint8Array(expected)) | ||
}); | ||
}) | ||
|
||
|
||
describe("base58", function () { | ||
test.each(base58Table)("encodes properly", function (plain, expected) { | ||
const actual = b58.encode(plain) | ||
expect(actual).toEqual(expected) | ||
}); | ||
|
||
test.each(base58Table)("decodes properly", function (expected, encoded) { | ||
const actual = b58.decode(encoded) | ||
expect(actual).toEqual(toUint8Array(expected)) | ||
}); | ||
}) | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { finalityThreshold } from "../src/constants/finality"; | ||
|
||
describe("Finality tests", function () { | ||
const mainnetFinality = finalityThreshold("Mainnet", "Ethereum"); | ||
it("should correctly access values", function () { | ||
expect(mainnetFinality).toEqual(64); | ||
}); | ||
}); | ||
|
Oops, something went wrong.