Skip to content

Commit

Permalink
fix: retry when a contract is not yet found (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr authored Aug 30, 2024
1 parent 2b993cd commit 46d8fc8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/token-processor/stacks-node/stacks-node-rpc-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class StacksNodeRpcClient {
`Runtime error while calling read-only function ${functionName}`
);
} else if (result.cause.includes('NoSuchContract')) {
throw new SmartContractClarityError(
throw new RetryableJobError(
`Contract not available yet when calling read-only function ${functionName}`
);
}
Expand Down
29 changes: 29 additions & 0 deletions tests/token-queue/process-token-job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -912,4 +912,33 @@ describe('ProcessTokenJob', () => {
expect(host).toBeUndefined();
});
});

test('Contract not found gets retried', async () => {
const nodeUrl = `http://${ENV.STACKS_NODE_RPC_HOST}:${ENV.STACKS_NODE_RPC_PORT}`;
const [tokenJob] = await insertAndEnqueueTestContractWithTokens(
db,
'ABCD.test-nft',
DbSipNumber.sip009,
1n
);

const mockResponse = {
okay: false,
cause: `Unchecked(NoSuchContract("ABCD.test-nft"))`,
};
const agent = new MockAgent();
agent.disableNetConnect();
agent
.get(nodeUrl)
.intercept({
path: `/v2/contracts/call-read/ABCD/test-nft/get-token-uri`,
method: 'POST',
})
.reply(200, mockResponse);
setGlobalDispatcher(agent);

await expect(new ProcessTokenJob({ db, job: tokenJob }).handler()).rejects.toThrow(
RetryableJobError
);
});
});
3 changes: 1 addition & 2 deletions tests/token-queue/stacks-node-rpc-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { StacksNodeRpcClient } from '../../src/token-processor/stacks-node/stack
import {
StacksNodeJsonParseError,
StacksNodeHttpError,
SmartContractClarityError,
} from '../../src/token-processor/util/errors';

describe('StacksNodeRpcClient', () => {
Expand Down Expand Up @@ -70,7 +69,7 @@ describe('StacksNodeRpcClient', () => {
setGlobalDispatcher(agent);

await expect(client.readStringFromContract('get-token-uri', [])).rejects.toThrow(
SmartContractClarityError
RetryableJobError
);
});

Expand Down

0 comments on commit 46d8fc8

Please sign in to comment.