Skip to content

Commit c88b741

Browse files
committed
[wip] fixing test
1 parent 43a4c49 commit c88b741

4 files changed

Lines changed: 42 additions & 30 deletions

File tree

packages/sequencer/src/protocol/baselayer/network-utils/LightnetUtils.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@ export class LightnetUtils implements MinaNetworkUtils {
105105

106106
tx.sign([faucetDonor]);
107107

108-
await this.transactionSender.signProveAndSendTransaction(
109-
tx,
110-
[faucetDonorPublicKey],
111-
"included"
112-
);
108+
await this.transactionSender.proveAndSendTransaction(tx, "included");
113109

114110
log.provable.info(
115111
`Funded account ${receiver.toBase58()} with ${fundingAmount / 1e9} MINA`

packages/sequencer/src/protocol/baselayer/network-utils/LocalBlockchainUtils.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ export class LocalBlockchainUtils implements MinaNetworkUtils {
8787

8888
tx.sign([faucetDonor]);
8989

90-
await this.transactionSender.signProveAndSendTransaction(
91-
tx,
92-
[faucetDonorPublicKey],
93-
"included"
94-
);
90+
await this.transactionSender.proveAndSendTransaction(tx, "included");
9591

9692
log.provable.info(
9793
`Funded account ${receiver.toBase58()} with ${fundingAmount / 1e9} MINA`

packages/sequencer/src/settlement/transactions/TxStatusWaiter.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ export class TxStatusWaiter {
5050

5151
public notifyIncluded(txId: string, hash: string) {
5252
this.getEmitter(txId).emit("included", { hash });
53-
this.emitters.delete(txId);
5453
}
5554

5655
public notifyFailed(txId: string, error: unknown) {
5756
this.getEmitter(txId).emit("failed", { error });
58-
this.emitters.delete(txId);
5957
}
6058

6159
private static isSatisfied(
@@ -90,7 +88,10 @@ export class TxStatusWaiter {
9088

9189
const emitter = this.getEmitter(txId);
9290
const eventPromise = new Promise<void>((resolve, reject) => {
93-
emitter.on(desiredStatus, () => resolve());
91+
emitter.on(desiredStatus, () => {
92+
resolve();
93+
this.emitters.delete(txId);
94+
});
9495
emitter.on("failed", ({ error }) => {
9596
reject(error instanceof Error ? error : new Error(String(error)));
9697
});

packages/sequencer/test/settlement/MinaTransactionSender.test.ts

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ type SenderFixture = {
3838
retryStrategy: any;
3939
};
4040

41+
type BaseLayerStub = {
42+
isLocalBlockChain: () => boolean;
43+
config: { network: { type: "local" | "remote" | "lightnet" } };
44+
};
45+
4146
function makeSender(
4247
pendingStorage: PendingL1TransactionStorage,
4348
dispatcherConfig: {
@@ -47,6 +52,10 @@ function makeSender(
4752
} = {
4853
pollIntervalMs: 5,
4954
statusCheckIntervalMs: 5,
55+
},
56+
baseLayerStub: BaseLayerStub = {
57+
isLocalBlockChain: () => true,
58+
config: { network: { type: "local" } },
5059
}
5160
): SenderFixture {
5261
const flowCreator = {
@@ -73,8 +82,6 @@ function makeSender(
7382
applyTransaction: jest.fn(async () => undefined),
7483
} as any;
7584

76-
const baseLayer = { config: { network: { type: "local" } } } as any;
77-
7885
const retryStrategy = {
7986
shouldRetry: jest.fn(async () => true),
8087
prepareRetryTransaction: jest.fn(async (record: any) => record.transaction),
@@ -89,13 +96,14 @@ function makeSender(
8996
retryStrategy as any,
9097
signer as any,
9198
waiter,
92-
dispatcherConfig
99+
dispatcherConfig,
100+
baseLayerStub as any
93101
);
94102
const sender = new MinaTransactionSender(
95103
flowCreator,
96104
provingTask,
97105
simulator,
98-
baseLayer,
106+
baseLayerStub as any,
99107
pendingStorage as any,
100108
signer,
101109
feeStrategy,
@@ -134,7 +142,6 @@ describe("MinaTransactionSender (unit)", () => {
134142
const pendingStorage: PendingL1TransactionStorage =
135143
new InMemoryPendingL1TransactionStorage();
136144
const { sender } = makeSender(pendingStorage);
137-
checkZkappTransactionStatus.mockResolvedValue({ success: false });
138145

139146
const { tx } = makeTx({ senderBase58: "S", nonce: 0, hash: "H1" });
140147

@@ -159,7 +166,6 @@ describe("MinaTransactionSender (unit)", () => {
159166
const pendingStorage: PendingL1TransactionStorage =
160167
new InMemoryPendingL1TransactionStorage();
161168
const { sender } = makeSender(pendingStorage);
162-
checkZkappTransactionStatus.mockResolvedValueOnce({ success: true });
163169

164170
const { tx } = makeTx({ senderBase58: "S", nonce: 0, hash: "H2" });
165171
try {
@@ -178,7 +184,6 @@ describe("MinaTransactionSender (unit)", () => {
178184
const pendingStorage: PendingL1TransactionStorage =
179185
new InMemoryPendingL1TransactionStorage();
180186
const { sender } = makeSender(pendingStorage);
181-
checkZkappTransactionStatus.mockResolvedValue({ success: false });
182187

183188
const tx0 = makeTx({ senderBase58: "S", nonce: 0, hash: "H0" });
184189
const tx1 = makeTx({ senderBase58: "S", nonce: 1, hash: "H1" });
@@ -202,11 +207,18 @@ describe("MinaTransactionSender (unit)", () => {
202207
it("should retry a transaction if first attempt fails", async () => {
203208
const pendingStorage: PendingL1TransactionStorage =
204209
new InMemoryPendingL1TransactionStorage();
205-
const { sender } = makeSender(pendingStorage, {
206-
pollIntervalMs: 5,
207-
statusCheckIntervalMs: 0,
208-
inclusionTimeoutMs: 0,
209-
});
210+
const { sender } = makeSender(
211+
pendingStorage,
212+
{
213+
pollIntervalMs: 5,
214+
statusCheckIntervalMs: 0,
215+
inclusionTimeoutMs: 0,
216+
},
217+
{
218+
isLocalBlockChain: () => false,
219+
config: { network: { type: "remote" } },
220+
}
221+
);
210222

211223
const { tx } = makeTx({ senderBase58: "S", nonce: 0, hash: "H-R1" });
212224

@@ -238,11 +250,18 @@ describe("MinaTransactionSender (unit)", () => {
238250
it("should stop retrying when shouldRetry returns false", async () => {
239251
const pendingStorage: PendingL1TransactionStorage =
240252
new InMemoryPendingL1TransactionStorage();
241-
const { sender, retryStrategy } = makeSender(pendingStorage, {
242-
pollIntervalMs: 5,
243-
statusCheckIntervalMs: 0,
244-
inclusionTimeoutMs: 0,
245-
});
253+
const { sender, retryStrategy } = makeSender(
254+
pendingStorage,
255+
{
256+
pollIntervalMs: 5,
257+
statusCheckIntervalMs: 0,
258+
inclusionTimeoutMs: 0,
259+
},
260+
{
261+
isLocalBlockChain: () => false,
262+
config: { network: { type: "remote" } },
263+
}
264+
);
246265

247266
// Force "no retry"
248267
retryStrategy.shouldRetry = jest.fn(async () => false);

0 commit comments

Comments
 (0)