@arkecosystem/typescript-crypto 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +23 -23
- package/.github/workflows/format.yml +80 -0
- package/.github/workflows/publish.yml +1 -1
- package/.prettierrc.json +8 -0
- package/dist/enums/ContractAbiType.d.ts.map +1 -1
- package/dist/exceptions/index.d.ts.map +1 -1
- package/dist/identities/PrivateKey.d.ts +2 -2
- package/dist/identities/PrivateKey.d.ts.map +1 -1
- package/dist/identities/PrivateKey.js +1 -1
- package/dist/identities/WIF.d.ts.map +1 -1
- package/dist/identities/WIF.js +2 -2
- package/dist/index.js +532 -626
- package/dist/networks/AbstractNetwork.d.ts +1 -1
- package/dist/networks/AbstractNetwork.d.ts.map +1 -1
- package/dist/networks/Mainnet.d.ts +1 -1
- package/dist/networks/Mainnet.d.ts.map +1 -1
- package/dist/networks/Mainnet.js +1 -1
- package/dist/networks/Testnet.d.ts +1 -1
- package/dist/networks/Testnet.d.ts.map +1 -1
- package/dist/networks/Testnet.js +1 -1
- package/dist/transactions/Deserializer.d.ts +5 -5
- package/dist/transactions/Deserializer.d.ts.map +1 -1
- package/dist/transactions/Deserializer.js +18 -18
- package/dist/transactions/Serializer.d.ts +0 -1
- package/dist/transactions/Serializer.d.ts.map +1 -1
- package/dist/transactions/Serializer.js +0 -3
- package/dist/transactions/builders/AbstractTransactionBuilder.d.ts +7 -6
- package/dist/transactions/builders/AbstractTransactionBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/AbstractTransactionBuilder.js +15 -8
- package/dist/transactions/builders/EvmCallBuilder.d.ts +3 -3
- package/dist/transactions/builders/EvmCallBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/MultipaymentBuilder.d.ts +5 -4
- package/dist/transactions/builders/MultipaymentBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/MultipaymentBuilder.js +6 -2
- package/dist/transactions/builders/TransferBuilder.d.ts +4 -3
- package/dist/transactions/builders/TransferBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/TransferBuilder.js +4 -0
- package/dist/transactions/builders/UnvoteBuilder.d.ts +3 -3
- package/dist/transactions/builders/UnvoteBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/UnvoteBuilder.js +1 -1
- package/dist/transactions/builders/UsernameRegistrationBuilder.d.ts +3 -3
- package/dist/transactions/builders/UsernameRegistrationBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/UsernameRegistrationBuilder.js +1 -1
- package/dist/transactions/builders/UsernameResignationBuilder.d.ts +3 -3
- package/dist/transactions/builders/UsernameResignationBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/UsernameResignationBuilder.js +1 -1
- package/dist/transactions/builders/ValidatorRegistrationBuilder.d.ts +3 -3
- package/dist/transactions/builders/ValidatorRegistrationBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/ValidatorRegistrationBuilder.js +4 -2
- package/dist/transactions/builders/ValidatorResignationBuilder.d.ts +3 -3
- package/dist/transactions/builders/ValidatorResignationBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/ValidatorResignationBuilder.js +1 -1
- package/dist/transactions/builders/VoteBuilder.d.ts +3 -3
- package/dist/transactions/builders/VoteBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/VoteBuilder.js +1 -1
- package/dist/transactions/types/AbstractTransaction.d.ts +2 -5
- package/dist/transactions/types/AbstractTransaction.d.ts.map +1 -1
- package/dist/transactions/types/AbstractTransaction.js +13 -15
- package/dist/transactions/types/EvmCall.d.ts +0 -3
- package/dist/transactions/types/EvmCall.d.ts.map +1 -1
- package/dist/transactions/types/EvmCall.js +0 -8
- package/dist/transactions/types/Multipayment.d.ts +1 -3
- package/dist/transactions/types/Multipayment.d.ts.map +1 -1
- package/dist/transactions/types/Multipayment.js +1 -8
- package/dist/transactions/types/Transfer.d.ts +0 -3
- package/dist/transactions/types/Transfer.d.ts.map +1 -1
- package/dist/transactions/types/Transfer.js +0 -8
- package/dist/transactions/types/Unvote.d.ts +0 -3
- package/dist/transactions/types/Unvote.d.ts.map +1 -1
- package/dist/transactions/types/Unvote.js +0 -8
- package/dist/transactions/types/UsernameRegistration.d.ts +1 -3
- package/dist/transactions/types/UsernameRegistration.d.ts.map +1 -1
- package/dist/transactions/types/UsernameRegistration.js +0 -7
- package/dist/transactions/types/UsernameResignation.d.ts +0 -3
- package/dist/transactions/types/UsernameResignation.d.ts.map +1 -1
- package/dist/transactions/types/UsernameResignation.js +0 -7
- package/dist/transactions/types/ValidatorRegistration.d.ts +1 -3
- package/dist/transactions/types/ValidatorRegistration.d.ts.map +1 -1
- package/dist/transactions/types/ValidatorRegistration.js +0 -8
- package/dist/transactions/types/ValidatorResignation.d.ts +0 -3
- package/dist/transactions/types/ValidatorResignation.d.ts.map +1 -1
- package/dist/transactions/types/ValidatorResignation.js +0 -8
- package/dist/transactions/types/Vote.d.ts +1 -3
- package/dist/transactions/types/Vote.d.ts.map +1 -1
- package/dist/transactions/types/Vote.js +0 -8
- package/dist/types.d.ts +19 -19
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/Abi/ArgumentDecoder.js +6 -6
- package/dist/utils/Abi/json/Abi.Consensus.json +15 -45
- package/dist/utils/Abi/json/Abi.Usernames.json +9 -27
- package/dist/utils/AbiDecoder.d.ts.map +1 -1
- package/dist/utils/AbiDecoder.js +3 -0
- package/dist/utils/AbiEncoder.d.ts +1 -1
- package/dist/utils/AbiEncoder.d.ts.map +1 -1
- package/dist/utils/AbiEncoder.js +2 -1
- package/dist/utils/Message.d.ts +1 -1
- package/dist/utils/Message.d.ts.map +1 -1
- package/dist/utils/Message.js +1 -1
- package/dist/utils/TransactionUtils.d.ts +0 -1
- package/dist/utils/TransactionUtils.d.ts.map +1 -1
- package/dist/utils/TransactionUtils.js +15 -18
- package/dist/utils/UnitConverter.d.ts.map +1 -1
- package/dist/utils/UnitConverter.js +12 -12
- package/eslint.config.mjs +19 -0
- package/jest.config.ts +6 -6
- package/package.json +6 -2
- package/src/enums/Constants.ts +1 -1
- package/src/enums/ContractAbiType.ts +4 -4
- package/src/exceptions/index.ts +1 -1
- package/src/identities/PrivateKey.ts +3 -3
- package/src/identities/WIF.ts +2 -3
- package/src/networks/AbstractNetwork.ts +3 -3
- package/src/networks/Mainnet.ts +3 -3
- package/src/networks/Testnet.ts +1 -1
- package/src/transactions/Deserializer.ts +39 -30
- package/src/transactions/Serializer.ts +1 -5
- package/src/transactions/builders/AbstractTransactionBuilder.ts +20 -11
- package/src/transactions/builders/EvmCallBuilder.ts +3 -3
- package/src/transactions/builders/MultipaymentBuilder.ts +13 -6
- package/src/transactions/builders/TransferBuilder.ts +8 -3
- package/src/transactions/builders/UnvoteBuilder.ts +4 -4
- package/src/transactions/builders/UsernameRegistrationBuilder.ts +4 -4
- package/src/transactions/builders/UsernameResignationBuilder.ts +4 -4
- package/src/transactions/builders/ValidatorRegistrationBuilder.ts +8 -5
- package/src/transactions/builders/ValidatorResignationBuilder.ts +4 -4
- package/src/transactions/builders/VoteBuilder.ts +4 -4
- package/src/transactions/types/AbstractTransaction.ts +17 -24
- package/src/transactions/types/EvmCall.ts +0 -15
- package/src/transactions/types/Multipayment.ts +3 -15
- package/src/transactions/types/Transfer.ts +0 -15
- package/src/transactions/types/Unvote.ts +0 -15
- package/src/transactions/types/UsernameRegistration.ts +1 -13
- package/src/transactions/types/UsernameResignation.ts +0 -14
- package/src/transactions/types/ValidatorRegistration.ts +1 -14
- package/src/transactions/types/ValidatorResignation.ts +0 -15
- package/src/transactions/types/Vote.ts +1 -14
- package/src/types.ts +19 -19
- package/src/utils/Abi/ArgumentDecoder.ts +6 -6
- package/src/utils/Abi/json/Abi.Consensus.json +1641 -1671
- package/src/utils/Abi/json/Abi.Multipayment.json +108 -108
- package/src/utils/Abi/json/Abi.Usernames.json +880 -898
- package/src/utils/AbiBase.ts +1 -1
- package/src/utils/AbiDecoder.ts +6 -3
- package/src/utils/AbiEncoder.ts +3 -2
- package/src/utils/Message.ts +1 -1
- package/src/utils/TransactionUtils.ts +24 -28
- package/src/utils/UnitConverter.ts +29 -29
- package/tests/fixtures/global.json +4 -4
- package/tests/fixtures/identity.json +10 -10
- package/tests/fixtures/transactions/evm-sign.json +4 -4
- package/tests/fixtures/transactions/multipayment-empty.json +4 -4
- package/tests/fixtures/transactions/multipayment-single.json +4 -4
- package/tests/fixtures/transactions/multipayment.json +4 -4
- package/tests/fixtures/transactions/transfer-0.json +4 -4
- package/tests/fixtures/transactions/transfer-large-amount.json +4 -4
- package/tests/fixtures/transactions/transfer.json +4 -4
- package/tests/fixtures/transactions/unvote.json +4 -4
- package/tests/fixtures/transactions/username-registration.json +4 -4
- package/tests/fixtures/transactions/username-resignation.json +4 -4
- package/tests/fixtures/transactions/validator-registration.json +4 -4
- package/tests/fixtures/transactions/validator-resignation.json +4 -4
- package/tests/fixtures/transactions/vote.json +4 -4
- package/tests/unit/configuration/Network.test.ts +52 -0
- package/tests/unit/identities/Address.test.ts +4 -4
- package/tests/unit/identities/PrivateKey.test.ts +5 -5
- package/tests/unit/identities/PublicKey.test.ts +9 -9
- package/tests/unit/identities/WIF.test.ts +1 -1
- package/tests/unit/transactions/Deserializer.test.ts +81 -63
- package/tests/unit/transactions/Serializer.test.ts +11 -1
- package/tests/unit/transactions/builders/EvmCallBuilder.test.ts +76 -9
- package/tests/unit/transactions/builders/MultipaymentBuilder.test.ts +125 -17
- package/tests/unit/transactions/builders/TransferBuilder.test.ts +146 -47
- package/tests/unit/transactions/builders/UnvoteBuilder.test.ts +75 -8
- package/tests/unit/transactions/builders/UsernameRegistrationBuilder.test.ts +75 -8
- package/tests/unit/transactions/builders/UsernameResignationBuilder.test.ts +75 -8
- package/tests/unit/transactions/builders/ValidatorRegistrationBuilder.test.ts +103 -8
- package/tests/unit/transactions/builders/ValidatorResignationBuilder.test.ts +75 -8
- package/tests/unit/transactions/builders/VoteBuilder.test.ts +75 -8
- package/tests/unit/transactions/types/AbstractTransaction.test.ts +27 -30
- package/tests/unit/transactions/types/EvmCall.test.ts +22 -0
- package/tests/unit/transactions/types/Multipayment.test.ts +38 -0
- package/tests/unit/transactions/types/Transfer.test.ts +18 -0
- package/tests/unit/transactions/types/Unvote.test.ts +18 -0
- package/tests/unit/transactions/types/UsernameRegistration.test.ts +22 -0
- package/tests/unit/transactions/types/UsernameResignation.test.ts +18 -0
- package/tests/unit/transactions/types/ValidatorRegistration.test.ts +22 -0
- package/tests/unit/transactions/types/ValidatorResignation.test.ts +18 -0
- package/tests/unit/transactions/types/Vote.test.ts +20 -0
- package/tests/unit/utils/Abi/ArgumentDecoder.test.ts +17 -16
- package/tests/unit/utils/AbiEncoder.test.ts +2 -2
- package/tests/unit/utils/Message.test.ts +1 -1
- package/tests/unit/utils/TransactionUtils.test.ts +1 -5
- package/tests/unit/utils/UnitConverter.test.ts +81 -47
- package/tsconfig.json +1 -1
- package/.eslintrc.js +0 -12
- package/prettier.config.js +0 -8
@@ -0,0 +1,18 @@
|
|
1
|
+
import { Transfer } from "@/transactions/types/Transfer";
|
2
|
+
import { AbstractTransaction } from "@/transactions/types/AbstractTransaction";
|
3
|
+
import fixture from "@tests/fixtures/transactions/transfer.json";
|
4
|
+
|
5
|
+
it("should create a new instance", () => {
|
6
|
+
const transaction = new Transfer(fixture.data);
|
7
|
+
|
8
|
+
expect(transaction).toBeInstanceOf(Transfer);
|
9
|
+
expect(transaction).toBeInstanceOf(AbstractTransaction);
|
10
|
+
|
11
|
+
expect(transaction.data.data).toEqual("");
|
12
|
+
});
|
13
|
+
|
14
|
+
it("should get payload", () => {
|
15
|
+
const transaction = new Transfer(fixture.data);
|
16
|
+
|
17
|
+
expect(transaction.getPayload()).toEqual("");
|
18
|
+
});
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { Unvote } from "@/transactions/types/Unvote";
|
2
|
+
import { AbstractTransaction } from "@/transactions/types/AbstractTransaction";
|
3
|
+
import fixture from "@tests/fixtures/transactions/unvote.json";
|
4
|
+
|
5
|
+
it("should create a new instance", () => {
|
6
|
+
const transaction = new Unvote(fixture.data);
|
7
|
+
|
8
|
+
expect(transaction).toBeInstanceOf(Unvote);
|
9
|
+
expect(transaction).toBeInstanceOf(AbstractTransaction);
|
10
|
+
|
11
|
+
expect(transaction.data.data).toEqual("3174b689");
|
12
|
+
});
|
13
|
+
|
14
|
+
it("should get payload", () => {
|
15
|
+
const transaction = new Unvote(fixture.data);
|
16
|
+
|
17
|
+
expect(transaction.getPayload()).toEqual("3174b689");
|
18
|
+
});
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { UsernameRegistration } from "@/transactions/types/UsernameRegistration";
|
2
|
+
import { AbstractTransaction } from "@/transactions/types/AbstractTransaction";
|
3
|
+
import fixture from "@tests/fixtures/transactions/username-registration.json";
|
4
|
+
|
5
|
+
it("should create a new instance", () => {
|
6
|
+
const transaction = new UsernameRegistration(fixture.data);
|
7
|
+
|
8
|
+
expect(transaction).toBeInstanceOf(UsernameRegistration);
|
9
|
+
expect(transaction).toBeInstanceOf(AbstractTransaction);
|
10
|
+
|
11
|
+
expect(transaction.data.data).toEqual(
|
12
|
+
"36a94134000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000076669787475726500000000000000000000000000000000000000000000000000",
|
13
|
+
);
|
14
|
+
});
|
15
|
+
|
16
|
+
it("should get payload", () => {
|
17
|
+
const transaction = new UsernameRegistration(fixture.data);
|
18
|
+
|
19
|
+
expect(transaction.getPayload()).toEqual(
|
20
|
+
"36a94134000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000076669787475726500000000000000000000000000000000000000000000000000",
|
21
|
+
);
|
22
|
+
});
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { UsernameResignation } from "@/transactions/types/UsernameResignation";
|
2
|
+
import { AbstractTransaction } from "@/transactions/types/AbstractTransaction";
|
3
|
+
import fixture from "@tests/fixtures/transactions/username-resignation.json";
|
4
|
+
|
5
|
+
it("should create a new instance", () => {
|
6
|
+
const transaction = new UsernameResignation(fixture.data);
|
7
|
+
|
8
|
+
expect(transaction).toBeInstanceOf(UsernameResignation);
|
9
|
+
expect(transaction).toBeInstanceOf(AbstractTransaction);
|
10
|
+
|
11
|
+
expect(transaction.data.data).toEqual("ebed6dab");
|
12
|
+
});
|
13
|
+
|
14
|
+
it("should get payload", () => {
|
15
|
+
const transaction = new UsernameResignation(fixture.data);
|
16
|
+
|
17
|
+
expect(transaction.getPayload()).toEqual("ebed6dab");
|
18
|
+
});
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { ValidatorRegistration } from "@/transactions/types/ValidatorRegistration";
|
2
|
+
import { AbstractTransaction } from "@/transactions/types/AbstractTransaction";
|
3
|
+
import fixture from "@tests/fixtures/transactions/validator-registration.json";
|
4
|
+
|
5
|
+
it("should create a new instance", () => {
|
6
|
+
const transaction = new ValidatorRegistration(fixture.data);
|
7
|
+
|
8
|
+
expect(transaction).toBeInstanceOf(ValidatorRegistration);
|
9
|
+
expect(transaction).toBeInstanceOf(AbstractTransaction);
|
10
|
+
|
11
|
+
expect(transaction.data.data).toEqual(
|
12
|
+
"602a9eee0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003030954f46d6097a1d314e900e66e11e0dad0a57cd03e04ec99f0dedd1c765dcb11e6d7fa02e22cf40f9ee23d9cc1c062400000000000000000000000000000000",
|
13
|
+
);
|
14
|
+
});
|
15
|
+
|
16
|
+
it("should get payload", () => {
|
17
|
+
const transaction = new ValidatorRegistration(fixture.data);
|
18
|
+
|
19
|
+
expect(transaction.getPayload()).toEqual(
|
20
|
+
"602a9eee0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003030954f46d6097a1d314e900e66e11e0dad0a57cd03e04ec99f0dedd1c765dcb11e6d7fa02e22cf40f9ee23d9cc1c062400000000000000000000000000000000",
|
21
|
+
);
|
22
|
+
});
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { ValidatorResignation } from "@/transactions/types/ValidatorResignation";
|
2
|
+
import { AbstractTransaction } from "@/transactions/types/AbstractTransaction";
|
3
|
+
import fixture from "@tests/fixtures/transactions/validator-resignation.json";
|
4
|
+
|
5
|
+
it("should create a new instance", () => {
|
6
|
+
const transaction = new ValidatorResignation(fixture.data);
|
7
|
+
|
8
|
+
expect(transaction).toBeInstanceOf(ValidatorResignation);
|
9
|
+
expect(transaction).toBeInstanceOf(AbstractTransaction);
|
10
|
+
|
11
|
+
expect(transaction.data.data).toEqual("b85f5da2");
|
12
|
+
});
|
13
|
+
|
14
|
+
it("should get payload", () => {
|
15
|
+
const transaction = new ValidatorResignation(fixture.data);
|
16
|
+
|
17
|
+
expect(transaction.getPayload()).toEqual("b85f5da2");
|
18
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { Vote } from "@/transactions/types/Vote";
|
2
|
+
import { AbstractTransaction } from "@/transactions/types/AbstractTransaction";
|
3
|
+
import fixture from "@tests/fixtures/transactions/vote.json";
|
4
|
+
|
5
|
+
it("should create a new instance", () => {
|
6
|
+
const transaction = new Vote(fixture.data);
|
7
|
+
|
8
|
+
expect(transaction).toBeInstanceOf(Vote);
|
9
|
+
expect(transaction).toBeInstanceOf(AbstractTransaction);
|
10
|
+
|
11
|
+
expect(transaction.data.data).toEqual("6dd7d8ea000000000000000000000000c3bbe9b1cee1ff85ad72b87414b0e9b7f2366763");
|
12
|
+
});
|
13
|
+
|
14
|
+
it("should get payload", () => {
|
15
|
+
const transaction = new Vote(fixture.data);
|
16
|
+
|
17
|
+
expect(transaction.getPayload()).toEqual(
|
18
|
+
"6dd7d8ea000000000000000000000000c3bbe9b1cee1ff85ad72b87414b0e9b7f2366763",
|
19
|
+
);
|
20
|
+
});
|
@@ -1,43 +1,44 @@
|
|
1
1
|
import { ArgumentDecoder } from "@/utils/Abi/ArgumentDecoder";
|
2
2
|
|
3
|
-
it(
|
4
|
-
const payload =
|
5
|
-
|
3
|
+
it("should decode string", () => {
|
4
|
+
const payload =
|
5
|
+
"0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000D48656C6C6F2C20776F726C642100000000000000000000000000000000000000";
|
6
|
+
const expected = "Hello, world!";
|
6
7
|
|
7
8
|
const decoder = new ArgumentDecoder(payload);
|
8
9
|
|
9
10
|
expect(decoder.decodeString()).toEqual(expected);
|
10
11
|
});
|
11
12
|
|
12
|
-
it(
|
13
|
-
const payload =
|
14
|
-
const expected =
|
13
|
+
it("should decode address", () => {
|
14
|
+
const payload = "000000000000000000000000512F366D524157BcF734546eB29a6d687B762255";
|
15
|
+
const expected = "0x512F366D524157BcF734546eB29a6d687B762255";
|
15
16
|
|
16
17
|
const decoder = new ArgumentDecoder(payload);
|
17
18
|
|
18
19
|
expect(decoder.decodeAddress()).toEqual(expected);
|
19
20
|
});
|
20
21
|
|
21
|
-
it(
|
22
|
-
const payload =
|
23
|
-
const expected =
|
22
|
+
it("should decode unsigned int", () => {
|
23
|
+
const payload = "000000000000000000000000000000000000000000000000016345785d8a0000";
|
24
|
+
const expected = "100000000000000000";
|
24
25
|
|
25
26
|
const decoder = new ArgumentDecoder(payload);
|
26
27
|
|
27
28
|
expect(decoder.decodeUnsignedInt()).toEqual(expected);
|
28
29
|
});
|
29
30
|
|
30
|
-
it(
|
31
|
-
const payload =
|
32
|
-
const expected =
|
31
|
+
it("should decode signed int", () => {
|
32
|
+
const payload = "000000000000000000000000000000000000000000000000016345785d8a0000";
|
33
|
+
const expected = "100000000000000000";
|
33
34
|
|
34
35
|
const decoder = new ArgumentDecoder(payload);
|
35
36
|
|
36
37
|
expect(decoder.decodeSignedInt()).toEqual(expected);
|
37
38
|
});
|
38
39
|
|
39
|
-
it(
|
40
|
-
const payload =
|
40
|
+
it("should decode bool as true", () => {
|
41
|
+
const payload = "0000000000000000000000000000000000000000000000000000000000000001";
|
41
42
|
const expected = true;
|
42
43
|
|
43
44
|
const decoder = new ArgumentDecoder(payload);
|
@@ -45,8 +46,8 @@ it('should decode bool as true', () => {
|
|
45
46
|
expect(decoder.decodeBool()).toEqual(expected);
|
46
47
|
});
|
47
48
|
|
48
|
-
it(
|
49
|
-
const payload =
|
49
|
+
it("should decode bool as false", () => {
|
50
|
+
const payload = "0000000000000000000000000000000000000000000000000000000000000000";
|
50
51
|
const expected = false;
|
51
52
|
|
52
53
|
const decoder = new ArgumentDecoder(payload);
|
@@ -6,7 +6,7 @@ it("should encode a vote function call", () => {
|
|
6
6
|
|
7
7
|
const functionName = "vote";
|
8
8
|
const args = ["0x512F366D524157BcF734546eB29a6d687B762255"];
|
9
|
-
const expectedEncodedData = "
|
9
|
+
const expectedEncodedData = "6dd7d8ea000000000000000000000000512f366d524157bcf734546eb29a6d687b762255";
|
10
10
|
|
11
11
|
const encodedData = encoder.encodeFunctionCall(functionName, args);
|
12
12
|
|
@@ -22,7 +22,7 @@ it("should encode a multipayment function call", () => {
|
|
22
22
|
["100000000", "200000000"],
|
23
23
|
];
|
24
24
|
const expectedEncodedData =
|
25
|
-
"
|
25
|
+
"084ce708000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000b693449adda7efc015d87944eae8b7c37eb1690a000000000000000000000000b693449adda7efc015d87944eae8b7c37eb1690a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000005f5e100000000000000000000000000000000000000000000000000000000000bebc200";
|
26
26
|
|
27
27
|
const encodedData = encoder.encodeFunctionCall(functionName, args);
|
28
28
|
|
@@ -71,7 +71,7 @@ describe("Message", () => {
|
|
71
71
|
describe("serialization", () => {
|
72
72
|
it("should turn a message into an array", async () => {
|
73
73
|
const message = Message.new(await getFixture("message-sign"));
|
74
|
-
const array = message.
|
74
|
+
const array = message.toObject();
|
75
75
|
|
76
76
|
expect(Array.isArray(array)).toBe(true);
|
77
77
|
expect(array.length).toBe(3);
|
@@ -16,7 +16,7 @@ it("should convert a transaction to a buffer without a signature", () => {
|
|
16
16
|
});
|
17
17
|
|
18
18
|
it("should convert a transaction to a hash with a signature", () => {
|
19
|
-
expect(TransactionUtils.toHash(fixture.data)).toBe(fixture.data.
|
19
|
+
expect(TransactionUtils.toHash(fixture.data)).toBe(fixture.data.hash);
|
20
20
|
});
|
21
21
|
|
22
22
|
it("should convert a transaction to a hash without a signature", () => {
|
@@ -25,7 +25,3 @@ it("should convert a transaction to a hash without a signature", () => {
|
|
25
25
|
expect(typeof hash).toBe("string");
|
26
26
|
expect(hash).toHaveLength(64);
|
27
27
|
});
|
28
|
-
|
29
|
-
it("should get a transaction id", () => {
|
30
|
-
expect(TransactionUtils.getId(fixture.data)).toBe(fixture.data.id);
|
31
|
-
});
|
@@ -1,71 +1,105 @@
|
|
1
1
|
import { UnitConverter } from "@/utils/UnitConverter";
|
2
2
|
|
3
|
-
it(
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
it.each([
|
4
|
+
[1, "1"],
|
5
|
+
[10, "10"],
|
6
|
+
[100, "100"],
|
7
|
+
[1000, "1000"],
|
8
|
+
[10000, "10000"],
|
9
|
+
])("should parse units into wei [%s]", (amount, formattedAmount) => {
|
10
|
+
const weiValue = UnitConverter.parseUnits(amount, "wei");
|
11
|
+
|
12
|
+
expect(weiValue.toString()).toEqual(formattedAmount);
|
7
13
|
});
|
8
14
|
|
9
|
-
it(
|
10
|
-
|
11
|
-
|
12
|
-
|
15
|
+
it.each([
|
16
|
+
[0.01, "10000000"],
|
17
|
+
[0.1, "100000000"],
|
18
|
+
[1, "1000000000"],
|
19
|
+
[10, "10000000000"],
|
20
|
+
[100, "100000000000"],
|
21
|
+
[1000, "1000000000000"],
|
22
|
+
[10000, "10000000000000"],
|
23
|
+
])("should parse units into gwei [%s]", (amount, formattedAmount) => {
|
24
|
+
const gweiValue = UnitConverter.parseUnits(amount, "gwei");
|
25
|
+
|
26
|
+
expect(gweiValue.toString()).toEqual(formattedAmount);
|
13
27
|
});
|
14
28
|
|
15
|
-
it(
|
16
|
-
|
17
|
-
|
18
|
-
|
29
|
+
it.each([
|
30
|
+
[0.01, "10000000000000000"],
|
31
|
+
[0.1, "100000000000000000"],
|
32
|
+
[1, "1000000000000000000"],
|
33
|
+
[10, "10000000000000000000"],
|
34
|
+
[100, "100000000000000000000"],
|
35
|
+
[1000, "1000000000000000000000"],
|
36
|
+
[10000, "10000000000000000000000"],
|
37
|
+
])("should parse units into ark [%s]", (amount, formattedAmount) => {
|
38
|
+
const arkValue = UnitConverter.parseUnits(amount, "ark");
|
39
|
+
|
40
|
+
expect(arkValue.toFixed()).toEqual(formattedAmount);
|
19
41
|
});
|
20
42
|
|
21
|
-
it(
|
22
|
-
|
43
|
+
it.each([
|
44
|
+
["1", 1],
|
45
|
+
["10", 10],
|
46
|
+
["100", 100],
|
47
|
+
["1000", 1000],
|
48
|
+
["10000", 10000],
|
49
|
+
])("should format units from wei [%s]", (formattedAmount, amount) => {
|
50
|
+
const formattedValue = UnitConverter.formatUnits(formattedAmount, "wei");
|
23
51
|
|
24
|
-
expect(
|
52
|
+
expect(formattedValue).toEqual(amount);
|
25
53
|
});
|
26
54
|
|
27
|
-
it(
|
28
|
-
|
55
|
+
it.each([
|
56
|
+
["1000000000", 1],
|
57
|
+
["10000000000", 10],
|
58
|
+
["100000000000", 100],
|
59
|
+
["1000000000000", 1000],
|
60
|
+
["10000000000000", 10000],
|
61
|
+
])("should format units from gwei [%s]", (formattedAmount, amount) => {
|
62
|
+
const formattedValue = UnitConverter.formatUnits(formattedAmount, "gwei");
|
29
63
|
|
30
|
-
expect(formattedValue).toEqual(
|
64
|
+
expect(formattedValue).toEqual(amount);
|
31
65
|
});
|
32
66
|
|
33
|
-
it(
|
34
|
-
|
67
|
+
it.each([
|
68
|
+
["1000000000000000000", 1],
|
69
|
+
["10000000000000000000", 10],
|
70
|
+
["100000000000000000000", 100],
|
71
|
+
["1000000000000000000000", 1000],
|
72
|
+
["10000000000000000000000", 10000],
|
73
|
+
])("should format units from ark [%s]", (formattedAmount, amount) => {
|
74
|
+
const formattedValue = UnitConverter.formatUnits(formattedAmount, "ark");
|
35
75
|
|
36
|
-
expect(formattedValue).toEqual(
|
76
|
+
expect(formattedValue).toEqual(amount);
|
37
77
|
});
|
38
78
|
|
39
|
-
it(
|
40
|
-
|
41
|
-
|
42
|
-
|
79
|
+
it("should throw exception for unsupported unit in parse", () => {
|
80
|
+
expect(() => UnitConverter.parseUnits(1, "unsupported")).toThrow(
|
81
|
+
"Unsupported unit: unsupported. Supported units are 'wei', 'gwei', and 'ark'.",
|
82
|
+
);
|
43
83
|
});
|
44
84
|
|
45
|
-
it(
|
46
|
-
expect(() => UnitConverter.
|
47
|
-
|
48
|
-
|
49
|
-
it('should throw exception for unsupported unit in format', () => {
|
50
|
-
expect(() => UnitConverter.formatUnits('1', 'unsupported')).toThrow("Unsupported unit: unsupported. Supported units are 'wei', 'gwei', and 'ark'.");
|
51
|
-
});
|
52
|
-
|
53
|
-
it('should parse units into ark with fraction', () => {
|
54
|
-
const arkValue = UnitConverter.parseUnits(0.1, 'ark');
|
55
|
-
|
56
|
-
expect(arkValue.toString()).toEqual('100000000000000000');
|
85
|
+
it("should throw exception for unsupported unit in format", () => {
|
86
|
+
expect(() => UnitConverter.formatUnits("1", "unsupported")).toThrow(
|
87
|
+
"Unsupported unit: unsupported. Supported units are 'wei', 'gwei', and 'ark'.",
|
88
|
+
);
|
57
89
|
});
|
58
90
|
|
59
|
-
it(
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
expect(UnitConverter.weiToArk(
|
91
|
+
it.each([
|
92
|
+
[1, "0.000000000000000001"],
|
93
|
+
["1000000000000000000", "1"],
|
94
|
+
])("should convert wei to ark [%s]", (amount, formattedAmount) => {
|
95
|
+
expect(UnitConverter.weiToArk(amount, "DARK")).toEqual(`${formattedAmount} DARK`);
|
96
|
+
expect(UnitConverter.weiToArk(amount)).toEqual(formattedAmount);
|
64
97
|
});
|
65
98
|
|
66
|
-
it(
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
expect(UnitConverter.gweiToArk(
|
99
|
+
it.each([
|
100
|
+
[1, "0.000000001"],
|
101
|
+
["1000000000", "1"],
|
102
|
+
])("should convert gwei to ark [%s]", (amount, formattedAmount) => {
|
103
|
+
expect(UnitConverter.gweiToArk(amount, "DARK")).toEqual(`${formattedAmount} DARK`);
|
104
|
+
expect(UnitConverter.gweiToArk(amount)).toEqual(formattedAmount);
|
71
105
|
});
|
package/tsconfig.json
CHANGED
package/.eslintrc.js
DELETED