Initial commit: USDT transfer worker (RabbitMQ + Postgres + Vault)
This commit is contained in:
24
tests/amount.test.ts
Normal file
24
tests/amount.test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { describe, it } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { formatUsdtAmount, parseUsdtAmount } from "../src/domain/amount.js";
|
||||
|
||||
void describe("USDT amount parsing", () => {
|
||||
void it("parses whole and fractional USDT with 6 decimals", () => {
|
||||
assert.equal(parseUsdtAmount("1"), 1_000_000n);
|
||||
assert.equal(parseUsdtAmount("1.234567"), 1_234_567n);
|
||||
assert.equal(parseUsdtAmount("0.000001"), 1n);
|
||||
});
|
||||
|
||||
void it("rejects zero, negative, malformed, and over-precise values", () => {
|
||||
assert.throws(() => parseUsdtAmount("0"), /greater than zero/);
|
||||
assert.throws(() => parseUsdtAmount("-1"), /valid decimal/);
|
||||
assert.throws(() => parseUsdtAmount("1.0000001"), /at most 6 decimals/);
|
||||
assert.throws(() => parseUsdtAmount("1e3"), /valid decimal/);
|
||||
});
|
||||
|
||||
void it("formats raw token units back to a trimmed USDT string", () => {
|
||||
assert.equal(formatUsdtAmount(1_234_567n), "1.234567");
|
||||
assert.equal(formatUsdtAmount(1_000_000n), "1");
|
||||
assert.equal(formatUsdtAmount(10n), "0.00001");
|
||||
});
|
||||
});
|
||||
19
tests/gasErrorMessage.test.ts
Normal file
19
tests/gasErrorMessage.test.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { describe, it } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { humanizeTransferError } from "../src/ethereum/EthersEthereumGateway.js";
|
||||
|
||||
void describe("humanizeTransferError", () => {
|
||||
void it("translates low gas price into a readable error", () => {
|
||||
const message = humanizeTransferError({
|
||||
message: "missing revert data",
|
||||
info: {
|
||||
error: {
|
||||
message:
|
||||
"failed with 3080732 gas: max fee per gas less than block base fee: address 0xabc, maxFeePerGas: 960000000, baseFee: 1575278655"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
assert.match(message, /Transfer fee 0.96 gwei is below current base fee 1.575278655 gwei/);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user