Skip to content

LW-9419 conway era unit tests #1188

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

Merged
merged 1 commit into from
Apr 3, 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
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,58 @@ describe('ChainHistoryBuilder', () => {
expect(result.size).toEqual(0);
});
});

describe('queryProposalProceduresByIds', () => {
test('query proposal procedures by tx hashes', async () => {
const txHashes = await fixtureBuilder.getTxHashes(1, { with: [TxWith.ProposalProcedures] });
const ids = await getTxIds(txHashes);
const result = await builder.queryProposalProceduresByIds(ids);
expect(result.size).toBeGreaterThanOrEqual(1);
const proposalProcedures = result.get(txHashes[0]);
expect(proposalProcedures).toBeDefined();
let infoAction;
for (const proposalProcedure of proposalProcedures!) {
if (proposalProcedure.governanceAction.__typename === Cardano.GovernanceActionType.info_action)
infoAction = proposalProcedure;
}
expect(infoAction).toBeDefined();
expect(infoAction).toMatchShapeOf(DataMocks.Tx.infoAction);
});
test('query proposal procedures with empty array', async () => {
const result = await builder.queryProposalProceduresByIds([]);
expect(result.size).toEqual(0);
});
test('query proposal procedures when tx not found', async () => {
const ids = await getTxIds([
Cardano.TransactionId('cefd2fcf657e5e5d6c35975f4e052f427819391b153ebb16ad8aa107ba5a3819')
]);
const result = await builder.queryProposalProceduresByIds(['0', ...ids]);
expect(result.size).toEqual(0);
});
});

describe('queryVotingProceduresByIds', () => {
test('query voting procedures by tx hashes', async () => {
const txHashes = await fixtureBuilder.getTxHashes(1, { with: [TxWith.VotingProcedure] });
const ids = await getTxIds(txHashes);
const result = await builder.queryVotingProceduresByIds(ids);
expect(result.size).toBeGreaterThanOrEqual(1);
const votingProcedures = result.get(txHashes[0]);
expect(votingProcedures).toBeDefined();
const vote = votingProcedures![0];
expect(vote).toBeDefined();
expect(vote).toMatchShapeOf(DataMocks.Tx.vote);
});
test('query voting procedures with empty array', async () => {
const result = await builder.queryVotingProceduresByIds([]);
expect(result.size).toEqual(0);
});
test('query voting procedures when tx not found', async () => {
const ids = await getTxIds([
Cardano.TransactionId('cefd2fcf657e5e5d6c35975f4e052f427819391b153ebb16ad8aa107ba5a3819')
]);
const result = await builder.queryVotingProceduresByIds(['0', ...ids]);
expect(result.size).toEqual(0);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export enum TxWith {
MultiAsset = 'multiAsset',
Redeemer = 'redeemer',
Withdrawal = 'withdrawal',
CollateralOutput = 'collateralOutput'
CollateralOutput = 'collateralOutput',
ProposalProcedures = 'proposalProcedures',
VotingProcedure = 'votingProcedures'
}

export type AddressesInBlockRange = {
Expand Down Expand Up @@ -122,6 +124,8 @@ export class ChainHistoryFixtureBuilder {
if (options.with.includes(TxWith.MirCertificate)) query += Queries.latestTxHashesWithMirCerts;
if (options.with.includes(TxWith.Withdrawal)) query += Queries.latestTxHashesWithWithdrawal;
if (options.with.includes(TxWith.CollateralOutput)) query += Queries.latestTxHashesWithCollateralOutput;
if (options.with.includes(TxWith.ProposalProcedures)) query += Queries.latestTxHashesWithProposalProcedures;
if (options.with.includes(TxWith.VotingProcedure)) query += Queries.latestTxHashesWithVotingProcedures;

query += Queries.endLatestTxHashes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ export const latestTxHashesWithWithdrawal = `
export const latestTxHashesWithCollateralOutput = `
JOIN collateral_tx_out ON collateral_tx_out.tx_id = tx.id`;

export const latestTxHashesWithProposalProcedures = `
JOIN gov_action_proposal ON gov_action_proposal.tx_id = tx.id`;

export const latestTxHashesWithVotingProcedures = `
JOIN voting_procedure ON voting_procedure.tx_id = tx.id`;

export const endLatestTxHashes = `
GROUP BY tx.id
ORDER BY tx.id DESC
Expand Down
26 changes: 26 additions & 0 deletions packages/cardano-services/test/data-mocks/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,32 @@ export const redeemer = {
purpose: 'spend'
};

export const infoAction = {
anchor: { dataHash: '3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d', url: 'https://testing.this' },
deposit: 1_000_000_000n,
governanceAction: { __typename: 'info_action' },
rewardAccount: 'stake_test1urc4mvzl2cp4gedl3yq2px7659krmzuzgnl2dpjjgsydmqqxgamj7'
};

export const vote = {
voter: {
__typename: 'dRepKeyHash',
credential: { hash: '4615beb10ff7b5d247dd0f8cb28ba447e8db9e7b4782b5d6eec7f1ed', type: 0 }
},
votes: [
{
actionId: { actionIndex: 0, id: 'c8686bd84d979285513a27e1c8dd4f6306c332df1b888ca5f2bb652945d78d64' },
votingProcedure: {
anchor: {
dataHash: '3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d',
url: 'https://testing.this'
},
vote: 2
}
}
]
};

export const tx = [
base,
certificate,
Expand Down
Loading