Skip to content

Commit

Permalink
Merge pull request #265 from hirosystems/develop
Browse files Browse the repository at this point in the history
release to master
  • Loading branch information
rafaelcr authored Sep 23, 2024
2 parents 0a04aab + 84252a7 commit 9f03edd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
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

0 comments on commit 9f03edd

Please sign in to comment.