-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patherrors.test.ts
More file actions
92 lines (75 loc) · 3.23 KB
/
Copy patherrors.test.ts
File metadata and controls
92 lines (75 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import * as Exceptions from "@mainsail/exceptions";
import { describe } from "@mainsail/test-runner";
describe<{
transaction: any;
}>("Errors", ({ it, assert, beforeAll }) => {
beforeAll((context) => {
context.transaction = {
amount: 100n,
gasPrice: 900 * 1e9,
hash: "dummy-tx-id",
network: 30,
nonce: 1n,
from: "dummy-sender-key",
type: 0,
hash: "dummy-tx-id",
key: "some-key",
serialized: Buffer.from("dummy"),
type: 0,
};
});
it("TransactionAlreadyInPoolError", (context) => {
const error = new Exceptions.TransactionAlreadyInPoolError(context.transaction);
assert.instance(error, Exceptions.PoolError);
assert.equal(error.type, "ERR_DUPLICATE");
assert.equal(error.message, `tx ${context.transaction.hash} is already in pool`);
});
it("TransactionExceedsMaximumByteSizeError", (context) => {
const error = new Exceptions.TransactionExceedsMaximumByteSizeError(context.transaction, 1024);
assert.instance(error, Exceptions.PoolError);
assert.equal(error.type, "ERR_TOO_LARGE");
assert.equal(error.message, `tx ${context.transaction.hash} exceeds size limit of 1024 byte(s)`);
});
it("TransactionFeeTooLowError", (context) => {
const error = new Exceptions.TransactionFeeTooLowError(context.transaction);
assert.instance(error, Exceptions.PoolError);
assert.equal(error.type, "ERR_LOW_FEE");
assert.equal(error.message, `tx ${context.transaction.hash} fee is too low to enter the pool`);
});
it("SenderExceededMaximumTransactionCountError", (context) => {
const error = new Exceptions.SenderExceededMaximumTransactionCountError(context.transaction, 1);
assert.instance(error, Exceptions.PoolError);
assert.equal(error.type, "ERR_EXCEEDS_MAX_COUNT");
assert.equal(error.message, `tx ${context.transaction.hash} exceeds sender's transaction count limit of 1`);
});
it("TransactionPoolFullError", (context) => {
const error = new Exceptions.TransactionPoolFullError(context.transaction, 1000 * 1e9);
assert.instance(error, Exceptions.PoolError);
assert.equal(error.type, "ERR_POOL_FULL");
assert.equal(
error.message,
`tx ${context.transaction.hash} fee 900000000000 is lower than 1000000000000 already in pool`,
);
});
it("TransactionFailedToApplyError", (context) => {
const error = new Exceptions.TransactionFailedToApplyError(
context.transaction,
new Error("Something went horribly wrong"),
);
assert.instance(error, Exceptions.PoolError);
assert.equal(error.type, "ERR_APPLY");
assert.equal(error.message, `tx ${context.transaction.hash} cannot be applied: Something went horribly wrong`);
});
it("TransactionFromWrongNetworkError", (context) => {
const error = new Exceptions.TransactionFromWrongNetworkError(context.transaction, 23);
assert.instance(error, Exceptions.PoolError);
assert.equal(error.type, "ERR_WRONG_NETWORK");
assert.equal(error.message, `tx ${context.transaction.hash} network 30 doesn't match node's network 23`);
});
it("InvalidTransactionDataError", (context) => {
const error = new Exceptions.InvalidTransactionDataError("Version 1 not supported");
assert.instance(error, Exceptions.PoolError);
assert.equal(error.type, "ERR_BAD_DATA");
assert.equal(error.message, "Invalid transaction data: Version 1 not supported");
});
});