Skip to content

Commit e33ac85

Browse files
committed
fixed yarn tests
1 parent b83daf4 commit e33ac85

File tree

13 files changed

+328
-317
lines changed

13 files changed

+328
-317
lines changed

packages/amino/src/coins.spec.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ describe("coins", () => {
1414
});
1515

1616
it("throws for non-safe-integer values", () => {
17-
expect(() => coin(1.23, "utoken")).toThrowError(/Given amount is not a safe integer/i);
18-
expect(() => coin(NaN, "utoken")).toThrowError(/Given amount is not a safe integer/i);
19-
expect(() => coin(Number.POSITIVE_INFINITY, "utoken")).toThrowError(
17+
expect(() => coin(1.23, "utoken")).toThrow(/Given amount is not a safe integer/i);
18+
expect(() => coin(NaN, "utoken")).toThrow(/Given amount is not a safe integer/i);
19+
expect(() => coin(Number.POSITIVE_INFINITY, "utoken")).toThrow(
2020
/Given amount is not a safe integer/i,
2121
);
22-
expect(() => coin(Number.MAX_SAFE_INTEGER + 1, "utoken")).toThrowError(
22+
expect(() => coin(Number.MAX_SAFE_INTEGER + 1, "utoken")).toThrow(
2323
/Given amount is not a safe integer/i,
2424
);
2525
});
2626

2727
it("throws for negative values", () => {
28-
expect(() => coin(-1, "utoken")).toThrowError(/Given amount is not a safe integer/i);
29-
expect(() => coin(Number.MIN_SAFE_INTEGER, "utoken")).toThrowError(
28+
expect(() => coin(-1, "utoken")).toThrow(/Given amount is not a safe integer/i);
29+
expect(() => coin(Number.MIN_SAFE_INTEGER, "utoken")).toThrow(
3030
/Given amount is not a safe integer/i,
3131
);
32-
expect(() => coin(Number.NEGATIVE_INFINITY, "utoken")).toThrowError(
32+
expect(() => coin(Number.NEGATIVE_INFINITY, "utoken")).toThrow(
3333
/Given amount is not a safe integer/i,
3434
);
3535
});
@@ -48,13 +48,13 @@ describe("coins", () => {
4848
});
4949

5050
it("throws for invalid amount strings", () => {
51-
expect(() => coin("-1", "utoken")).toThrowError(/Invalid unsigned integer string format/i);
52-
expect(() => coin("0x01", "utoken")).toThrowError(/Invalid unsigned integer string format/i);
53-
expect(() => coin("NaN", "utoken")).toThrowError(/Invalid unsigned integer string format/i);
54-
expect(() => coin("1.0", "utoken")).toThrowError(/Invalid unsigned integer string format/i);
55-
expect(() => coin("1 ", "utoken")).toThrowError(/Invalid unsigned integer string format/i);
56-
expect(() => coin(" 1", "utoken")).toThrowError(/Invalid unsigned integer string format/i);
57-
expect(() => coin("1.1827350506e+26", "utoken")).toThrowError(
51+
expect(() => coin("-1", "utoken")).toThrow(/Invalid unsigned integer string format/i);
52+
expect(() => coin("0x01", "utoken")).toThrow(/Invalid unsigned integer string format/i);
53+
expect(() => coin("NaN", "utoken")).toThrow(/Invalid unsigned integer string format/i);
54+
expect(() => coin("1.0", "utoken")).toThrow(/Invalid unsigned integer string format/i);
55+
expect(() => coin("1 ", "utoken")).toThrow(/Invalid unsigned integer string format/i);
56+
expect(() => coin(" 1", "utoken")).toThrow(/Invalid unsigned integer string format/i);
57+
expect(() => coin("1.1827350506e+26", "utoken")).toThrow(
5858
/Invalid unsigned integer string format/i,
5959
);
6060
});
@@ -221,24 +221,24 @@ describe("coins", () => {
221221

222222
it("throws for invalid inputs", () => {
223223
// denom missing
224-
expect(() => parseCoins("3456")).toThrowError(/invalid coin string/i);
224+
expect(() => parseCoins("3456")).toThrow(/invalid coin string/i);
225225

226226
// amount missing
227-
expect(() => parseCoins("ucosm")).toThrowError(/invalid coin string/i);
227+
expect(() => parseCoins("ucosm")).toThrow(/invalid coin string/i);
228228

229229
// denom starting with slash
230-
expect(() => parseCoins("3456/ibc")).toThrowError(/invalid coin string/i);
230+
expect(() => parseCoins("3456/ibc")).toThrow(/invalid coin string/i);
231231

232232
// denom too short
233-
expect(() => parseCoins("3456a")).toThrowError(/invalid coin string/i);
234-
expect(() => parseCoins("3456aa")).toThrowError(/invalid coin string/i);
233+
expect(() => parseCoins("3456a")).toThrow(/invalid coin string/i);
234+
expect(() => parseCoins("3456aa")).toThrow(/invalid coin string/i);
235235

236236
// denom too long
237237
expect(() =>
238238
parseCoins(
239239
"3456abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefgha",
240240
),
241-
).toThrowError(/invalid coin string/i);
241+
).toThrow(/invalid coin string/i);
242242
});
243243
});
244244

@@ -271,7 +271,7 @@ describe("coins", () => {
271271
amount: "20000",
272272
denom: "ucosm",
273273
};
274-
expect(() => addCoins(balance1, balance2)).toThrowError(
274+
expect(() => addCoins(balance1, balance2)).toThrow(
275275
/Trying to add two coins with different denoms/i,
276276
);
277277
});

packages/amino/src/encoding.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe("encoding", () => {
3535
const pubkey = fromBase64(
3636
"BE8EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQE7WHpoHoNswYeoFkuYpYSKK4mzFzMV/dB0DVAy4lnNU=",
3737
);
38-
expect(() => encodeSecp256k1Pubkey(pubkey)).toThrowError(/public key must be compressed secp256k1/i);
38+
expect(() => encodeSecp256k1Pubkey(pubkey)).toThrow(/public key must be compressed secp256k1/i);
3939
});
4040
});
4141

@@ -49,10 +49,10 @@ describe("encoding", () => {
4949
});
5050

5151
it("throws for wrong pubkey lengths", () => {
52-
expect(() => encodeEd25519Pubkey(Random.getBytes(31))).toThrowError(
52+
expect(() => encodeEd25519Pubkey(Random.getBytes(31))).toThrow(
5353
/ed25519 public key must be 32 bytes long/i,
5454
);
55-
expect(() => encodeEd25519Pubkey(Random.getBytes(64))).toThrowError(
55+
expect(() => encodeEd25519Pubkey(Random.getBytes(64))).toThrow(
5656
/ed25519 public key must be 32 bytes long/i,
5757
);
5858
});
@@ -129,7 +129,7 @@ describe("encoding", () => {
129129
},
130130
});
131131

132-
expect(() => decodeAminoPubkey(fromHex("22C1F7E20705"))).toThrowError(/expecting 0x08 prefix/i);
132+
expect(() => decodeAminoPubkey(fromHex("22C1F7E20705"))).toThrow(/expecting 0x08 prefix/i);
133133
});
134134
});
135135

packages/amino/src/multisig.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ describe("multisig", () => {
7373
});
7474

7575
it("throws for threshold larger than number of keys", () => {
76-
expect(() => createMultisigThresholdPubkey([test1, test2, test3], 4)).toThrowError(
76+
expect(() => createMultisigThresholdPubkey([test1, test2, test3], 4)).toThrow(
7777
/threshold k = 4 exceeds number of keys n = 3/i,
7878
);
79-
expect(() => createMultisigThresholdPubkey([test1, test2, test3], 75)).toThrowError(
79+
expect(() => createMultisigThresholdPubkey([test1, test2, test3], 75)).toThrow(
8080
/threshold k = 75 exceeds number of keys n = 3/i,
8181
);
8282
});

packages/amino/src/signature.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("signature", () => {
2626
const signature = fromBase64(
2727
"1nUcIH0CLT0/nQ0mBTDrT6kMG20NY/PsH7P2gc4bpYNGLEYjBmdWevXUJouSE/9A/60QG9cYeqyTe5kFDeIPxQ==",
2828
);
29-
expect(() => encodeSecp256k1Signature(pubkey, signature)).toThrowError(
29+
expect(() => encodeSecp256k1Signature(pubkey, signature)).toThrow(
3030
/public key must be compressed secp256k1/i,
3131
);
3232
});
@@ -39,7 +39,7 @@ describe("signature", () => {
3939
),
4040
99,
4141
]);
42-
expect(() => encodeSecp256k1Signature(pubkey, signature)).toThrowError(
42+
expect(() => encodeSecp256k1Signature(pubkey, signature)).toThrow(
4343
/signature must be 64 bytes long/i,
4444
);
4545
});

packages/auth/src/keys/private-key.spec.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,119 @@
11
import { HDPath } from '@interchainjs/types';
22
import { BaseCryptoBytes } from '@interchainjs/utils';
33
import { PrivateKey } from './private-key';
4-
import { createCosmosConfig, createEthereumConfig } from '../config/builders';
4+
import { createCosmosConfig } from '../../../../networks/cosmos/src/auth/config';
5+
import { createEthereumConfig } from '../../../../networks/ethereum/src/auth/config';
56

67
describe('PrivateKey', () => {
78
const testMnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
8-
9+
910
describe('fromMnemonic', () => {
1011
it('should create private keys from mnemonic for Cosmos', async () => {
1112
const hdPaths = [
1213
HDPath.cosmos(0, 0, 0),
1314
HDPath.cosmos(0, 0, 1),
1415
];
15-
16+
1617
const config = createCosmosConfig().privateKeyConfig;
1718
const privateKeys = await PrivateKey.fromMnemonic(testMnemonic, hdPaths, config);
18-
19+
1920
expect(privateKeys).toHaveLength(2);
2021
expect(privateKeys[0].hdPath?.toString()).toBe('m/44\'/118\'/0\'/0/0');
2122
expect(privateKeys[1].hdPath?.toString()).toBe('m/44\'/118\'/0\'/0/1');
2223
});
23-
24+
2425
it('should create private keys from mnemonic for Ethereum', async () => {
2526
const hdPath = HDPath.eth(0, 0, 0);
2627
const config = createEthereumConfig().privateKeyConfig;
2728
const privateKeys = await PrivateKey.fromMnemonic(testMnemonic, [hdPath], config);
28-
29+
2930
expect(privateKeys).toHaveLength(1);
3031
expect(privateKeys[0].hdPath?.toString()).toBe('m/44\'/60\'/0\'/0/0');
3132
});
3233
});
33-
34+
3435
describe('fromHex', () => {
3536
it('should create private key from hex string', () => {
3637
const hexKey = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';
3738
const config = createCosmosConfig().privateKeyConfig;
38-
39+
3940
const privateKey = PrivateKey.fromHex(hexKey, config);
40-
41+
4142
expect(privateKey.toHex()).toBe(hexKey);
4243
expect(privateKey.config.algo).toBe('secp256k1');
4344
});
4445
});
45-
46+
4647
describe('fromBytes', () => {
4748
it('should create private key from bytes', () => {
4849
const bytes = new Uint8Array(32).fill(42);
4950
const cryptoBytes = BaseCryptoBytes.from(bytes);
5051
const config = createCosmosConfig().privateKeyConfig;
51-
52+
5253
const privateKey = PrivateKey.fromBytes(cryptoBytes, config);
53-
54+
5455
expect(privateKey.value.value).toEqual(bytes);
5556
expect(privateKey.config.algo).toBe('secp256k1');
5657
});
5758
});
58-
59+
5960
describe('toPublicKey', () => {
6061
it('should derive public key with default compression', async () => {
6162
const hdPath = HDPath.cosmos(0, 0, 0);
6263
const config = createCosmosConfig().privateKeyConfig;
6364
const privateKeys = await PrivateKey.fromMnemonic(testMnemonic, [hdPath], config);
64-
65+
6566
const publicKey = privateKeys[0].toPublicKey();
66-
67+
6768
expect(publicKey.compressed).toBe(true);
6869
expect(publicKey.algo).toBe('secp256k1');
6970
});
70-
71+
7172
it('should derive public key with custom compression', async () => {
7273
const hdPath = HDPath.eth(0, 0, 0);
7374
const config = createEthereumConfig().privateKeyConfig;
7475
const privateKeys = await PrivateKey.fromMnemonic(testMnemonic, [hdPath], config);
75-
76+
7677
const publicKey = privateKeys[0].toPublicKey({ compressed: false });
77-
78+
7879
expect(publicKey.compressed).toBe(false);
7980
expect(publicKey.algo).toBe('secp256k1');
8081
});
8182
});
82-
83+
8384
describe('sign', () => {
8485
it('should sign data', async () => {
8586
const hdPath = HDPath.cosmos(0, 0, 0);
8687
const config = createCosmosConfig().privateKeyConfig;
8788
const privateKeys = await PrivateKey.fromMnemonic(testMnemonic, [hdPath], config);
88-
89+
8990
const message = new TextEncoder().encode('Hello, InterchainJS!');
9091
const signature = await privateKeys[0].sign(message);
91-
92+
9293
expect(signature).toBeDefined();
9394
expect(signature.value).toBeInstanceOf(Uint8Array);
9495
expect(signature.value.length).toBeGreaterThan(0);
9596
});
9697
});
97-
98+
9899
describe('serialization', () => {
99100
it('should convert to hex', async () => {
100101
const hdPath = HDPath.cosmos(0, 0, 0);
101102
const config = createCosmosConfig().privateKeyConfig;
102103
const privateKeys = await PrivateKey.fromMnemonic(testMnemonic, [hdPath], config);
103-
104+
104105
const hex = privateKeys[0].toHex();
105-
106+
106107
expect(hex).toMatch(/^[0-9a-f]{64}$/);
107108
});
108-
109+
109110
it('should convert to base64', async () => {
110111
const hdPath = HDPath.cosmos(0, 0, 0);
111112
const config = createCosmosConfig().privateKeyConfig;
112113
const privateKeys = await PrivateKey.fromMnemonic(testMnemonic, [hdPath], config);
113-
114+
114115
const base64 = privateKeys[0].toBase64();
115-
116+
116117
expect(base64).toMatch(/^[A-Za-z0-9+/]+=*$/);
117118
});
118119
});

0 commit comments

Comments
 (0)