Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release to master #265

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/pg/chainhook/block-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class BlockCache {
}

transaction(tx: StacksTransaction) {
if (!tx.metadata.success) return;
if (tx.metadata.kind.type === 'ContractDeployment' && tx.metadata.contract_abi) {
const abi = tx.metadata.contract_abi as ClarityAbi;
const sip = getSmartContractSip(abi);
Expand Down
17 changes: 17 additions & 0 deletions tests/chainhook/smart-contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ describe('contract deployments', () => {
await expect(db.getPendingJobBatch({ limit: 1 })).resolves.toHaveLength(1);
});

test('ignores token contract from a failed transaction', async () => {
await db.chainhook.processPayload(
new TestChainhookPayloadBuilder()
.apply()
.block({ height: 100 })
.transaction({
hash: '0x01',
sender: 'SP1K1A1PMGW2ZJCNF46NWZWHG8TS1D23EGH1KNK60',
success: false, // Failed
})
.contractDeploy('SP1K1A1PMGW2ZJCNF46NWZWHG8TS1D23EGH1KNK60.friedger-pool-nft', SIP_009_ABI)
.build()
);
await expect(db.getSmartContract({ id: 1 })).resolves.toBeUndefined();
await expect(db.getPendingJobBatch({ limit: 1 })).resolves.toHaveLength(0);
});

test('ignores non-token contract', async () => {
await db.chainhook.processPayload(
new TestChainhookPayloadBuilder()
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ export class TestChainhookPayloadBuilder {
return this;
}

transaction(args: { hash: string; sender?: string }): this {
transaction(args: { hash: string; sender?: string; success?: boolean }): this {
this.lastBlock.transactions.push({
metadata: {
contract_abi: null,
Expand All @@ -1367,7 +1367,7 @@ export class TestChainhookPayloadBuilder {
},
result: '(ok true)',
sender: args.sender ?? 'SP3HXJJMJQ06GNAZ8XWDN1QM48JEDC6PP6W3YZPZJ',
success: true,
success: args.success ?? true,
},
operations: [],
transaction_identifier: {
Expand Down
Loading