Skip to content

Commit d801475

Browse files
committed
Use wallet name lookup in SIP-031 stateful test logs
Maybe there's a better way via clarigen, but not known at time of writing.
1 parent 632ab2b commit d801475

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

contrib/core-contract-tests/tests/sip-031/commands/Claim.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import fc from "fast-check";
22
import type { Model, Real } from "./types";
3-
import { calculateClaimable, logCommand, trackCommandRun } from "./utils";
3+
import {
4+
calculateClaimable,
5+
getWalletNameByAddress,
6+
logCommand,
7+
trackCommandRun,
8+
} from "./utils";
49
import { expect } from "vitest";
510
import { txOk } from "@clarigen/test";
611

@@ -26,7 +31,7 @@ export const Claim = (accounts: Real["accounts"]) =>
2631
model.totalClaimed += expectedClaim;
2732

2833
logCommand({
29-
sender: r.sender,
34+
sender: getWalletNameByAddress(r.sender),
3035
status: "ok",
3136
action: "claim",
3237
value: `amount ${expectedClaim}`,

contrib/core-contract-tests/tests/sip-031/commands/ClaimErr.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import fc from "fast-check";
22
import type { Model, Real } from "./types";
3-
import { calculateClaimable, logCommand, trackCommandRun } from "./utils";
3+
import {
4+
calculateClaimable,
5+
getWalletNameByAddress,
6+
logCommand,
7+
trackCommandRun,
8+
} from "./utils";
49
import { expect } from "vitest";
510
import { txErr } from "@clarigen/test";
611

@@ -35,7 +40,7 @@ export const ClaimErr = (accounts: Real["accounts"]) =>
3540
? "ERR_NOT_ALLOWED"
3641
: "ERR_NOTHING_TO_CLAIM";
3742
logCommand({
38-
sender: r.sender,
43+
sender: getWalletNameByAddress(r.sender),
3944
status: "err",
4045
action: "claim-err",
4146
error: errString,

contrib/core-contract-tests/tests/sip-031/commands/UpdateRecipient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fc from "fast-check";
22
import type { Model, Real } from "./types";
33
import { expect } from "vitest";
44
import { txOk } from "@clarigen/test";
5-
import { logCommand, trackCommandRun } from "./utils";
5+
import { getWalletNameByAddress, logCommand, trackCommandRun } from "./utils";
66

77
export const UpdateRecipient = (accounts: Real["accounts"]) =>
88
fc.record({
@@ -30,10 +30,10 @@ export const UpdateRecipient = (accounts: Real["accounts"]) =>
3030
model.recipient = r.newRecipient;
3131

3232
logCommand({
33-
sender: r.sender,
33+
sender: getWalletNameByAddress(r.sender),
3434
status: "ok",
3535
action: "update-recipient",
36-
value: `to ${r.newRecipient}`,
36+
value: `to ${getWalletNameByAddress(r.newRecipient)}`,
3737
});
3838
},
3939
toString: () => `update-recipient to ${r.newRecipient}`,

contrib/core-contract-tests/tests/sip-031/commands/UpdateRecipientErr.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fc from "fast-check";
22
import type { Model, Real } from "./types";
33
import { expect } from "vitest";
44
import { txErr } from "@clarigen/test";
5-
import { logCommand, trackCommandRun } from "./utils";
5+
import { getWalletNameByAddress, logCommand, trackCommandRun } from "./utils";
66

77
export const UpdateRecipientErr = (accounts: Real["accounts"]) =>
88
fc.record({
@@ -26,7 +26,7 @@ export const UpdateRecipientErr = (accounts: Real["accounts"]) =>
2626
expect(receipt.value).toBe(model.constants.ERR_NOT_ALLOWED);
2727

2828
logCommand({
29-
sender: r.sender,
29+
sender: getWalletNameByAddress(r.sender),
3030
status: "err",
3131
action: "update-recipient-err",
3232
error: "ERR_NOT_ALLOWED",

contrib/core-contract-tests/tests/sip-031/commands/utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Model } from "./types";
2+
import { accounts } from "../../clarigen-types";
23

34
export function calculateClaimable(model: Readonly<Model>): bigint {
45
const c = model.constants;
@@ -35,7 +36,7 @@ export function logCommand({
3536
value?: string | number | bigint;
3637
error?: string;
3738
}) {
38-
const senderStr = (sender ?? "system").padEnd(41, " ");
39+
const senderStr = (sender ?? "system").padEnd(11, " ");
3940
const statusStr = status === "ok" ? "✓" : "✗";
4041
const actionStr = action.padEnd(22, " ");
4142

@@ -96,4 +97,7 @@ function logAsTree(statistics: [string, number][]) {
9697
};
9798

9899
printTree(tree);
99-
}
100+
}
101+
102+
export const getWalletNameByAddress = (address: string): string | undefined =>
103+
Object.entries(accounts).find(([, v]) => v.address === address)?.[0];

0 commit comments

Comments
 (0)