Skip to content

Commit

Permalink
Fix integration tests (#66)
Browse files Browse the repository at this point in the history
* Remove transaction fields from test query

* Add transaction fields to test cases
  • Loading branch information
JonoPrest authored Jul 11, 2024
1 parent c4324e1 commit f7ea343
Show file tree
Hide file tree
Showing 8 changed files with 2,033 additions and 75 deletions.
73 changes: 45 additions & 28 deletions codegenerator/integration_tests/tests/evm_Erc20.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const assert = require("assert");
const { exit } = require("process");
const { fetchQueryWithTestCallback } = require("./graphqlFetchWithTestCallback");
const {
fetchQueryWithTestCallback,
} = require("./graphqlFetchWithTestCallback");

const maxRetryFailureMessage = "Max retries reached - either increase the timeout (maxRetries) or check for other bugs."
const maxRetryFailureMessage =
"Max retries reached - either increase the timeout (maxRetries) or check for other bugs.";

const pollGraphQL = async () => {
const rawEventsQuery = `
Expand All @@ -11,8 +14,6 @@ const pollGraphQL = async () => {
event_type
log_index
src_address
transaction_hash
transaction_index
block_number
}
}
Expand All @@ -32,45 +33,61 @@ const pollGraphQL = async () => {
}
`;

console.log("Starting erc20 tests - raw events approval event test")
console.log("Starting erc20 tests - raw events approval event test");
// TODO: make this use promises rather than callbacks.
fetchQueryWithTestCallback(rawEventsQuery, maxRetryFailureMessage, (data) => {
let shouldExitOnFailure = false;
try {
assert(
data.raw_events_by_pk.event_type === "ERC20_Approval",
"event_type should be an Approval"
"event_type should be an Approval",
);
console.log("First erc20 test passed, running account entity test.");


// Run the second test
fetchQueryWithTestCallback(accountEntityQuery, maxRetryFailureMessage, ({ Account_by_pk: account }) => {
try {
assert(!!account, "account should not be null or undefined");
shouldExitOnFailure = true;
fetchQueryWithTestCallback(
accountEntityQuery,
maxRetryFailureMessage,
({ Account_by_pk: account }) => {
try {
assert(!!account, "account should not be null or undefined");
shouldExitOnFailure = true;

assert(account.balance > 311465476000000000000, "balance should be == 70"); // NOTE the balance shouldn't change since we own this erc20 token.
assert(account.approvals.length > 0, "There should be at least one approval");
assert(account.approvals[0].amount == 79228162514264337593543950335n, "The first approval amount should be 50");
assert(account.approvals[0].owner_id == account.id, "The first approval owner should be the account id");
assert(account.approvals[0].spender_id == "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D", "The first approval spender should be correct (from uniswap)");
}
catch (err) {
//gotta love javascript
err.shouldExitOnFailure = shouldExitOnFailure
throw err;
}
console.log("Second test passed.");
});
}
catch (err) {
assert(
account.balance > 311465476000000000000,
"balance should be == 70",
); // NOTE the balance shouldn't change since we own this erc20 token.
assert(
account.approvals.length > 0,
"There should be at least one approval",
);
assert(
account.approvals[0].amount == 79228162514264337593543950335n,
"The first approval amount should be 50",
);
assert(
account.approvals[0].owner_id == account.id,
"The first approval owner should be the account id",
);
assert(
account.approvals[0].spender_id ==
"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
"The first approval spender should be correct (from uniswap)",
);
} catch (err) {
//gotta love javascript
err.shouldExitOnFailure = shouldExitOnFailure;
throw err;
}
console.log("Second test passed.");
},
);
} catch (err) {
//gotta love javascript
err.shouldExitOnFailure = shouldExitOnFailure
err.shouldExitOnFailure = shouldExitOnFailure;
throw err;
}
});
};

pollGraphQL();

56 changes: 32 additions & 24 deletions codegenerator/integration_tests/tests/evm_Greeter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const assert = require("assert");
const { fetchQueryWithTestCallback } = require("./graphqlFetchWithTestCallback");
const {
fetchQueryWithTestCallback,
} = require("./graphqlFetchWithTestCallback");

const maxRetryFailureMessage = "Max retries reached - either increase the timeout (maxRetries) or check for other bugs."
const maxRetryFailureMessage =
"Max retries reached - either increase the timeout (maxRetries) or check for other bugs.";

const pollGraphQL = async () => {
const rawEventsQuery = `
Expand All @@ -10,8 +13,6 @@ const pollGraphQL = async () => {
event_type
log_index
src_address
transaction_hash
transaction_index
block_number
}
}
Expand All @@ -34,34 +35,41 @@ const pollGraphQL = async () => {
try {
assert(
data.raw_events_by_pk.event_type === "Greeter_NewGreeting",
"event_type should be Greeter_NewGreeting"
"event_type should be Greeter_NewGreeting",
);
console.log(
"First greeter passed, running the second one for user entity",
);
console.log("First greeter passed, running the second one for user entity");

// Run the second test
fetchQueryWithTestCallback(userEntityQuery, maxRetryFailureMessage, ({ User_by_pk: user }) => {
try {
assert(!!user, "greeting should not be null or undefined");
assert(
user.greetings.slice(0, 3).toString() === "gm,gn,gm paris",
"First 3 greetings should be 'gm,gn,gm paris'"
);
assert(user.numberOfGreetings >= 3, "numberOfGreetings should be >= 3");
console.log("Second test passed.");
}
catch (err) {
//gotta love javascript
err.shouldExitOnFailure = shouldExitOnFailure
throw err;
}
});
fetchQueryWithTestCallback(
userEntityQuery,
maxRetryFailureMessage,
({ User_by_pk: user }) => {
try {
assert(!!user, "greeting should not be null or undefined");
assert(
user.greetings.slice(0, 3).toString() === "gm,gn,gm paris",
"First 3 greetings should be 'gm,gn,gm paris'",
);
assert(
user.numberOfGreetings >= 3,
"numberOfGreetings should be >= 3",
);
console.log("Second test passed.");
} catch (err) {
//gotta love javascript
err.shouldExitOnFailure = shouldExitOnFailure;
throw err;
}
},
);
} catch (err) {
//gotta love javascript
err.shouldExitOnFailure = shouldExitOnFailure
err.shouldExitOnFailure = shouldExitOnFailure;
throw err;
}
});

};

pollGraphQL();
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# yaml-language-server: $schema=../../../../cli/npm/envio/evm.schema.json
name: kwenta-factory-example
field_selection:
transaction_fields:
- hash
- transaction_index
networks:
- id: 10
start_block: 4556306
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ FuturesMarket.CacheUpdated.handler(async ({ event, context }) => {
};

const futuresMarket_CacheUpdatedEntity: FuturesMarket_CacheUpdated = {
id: event.transactionHash + event.logIndex.toString(),
id: event.transaction.hash + event.logIndex.toString(),
name: event.params.name,
destination: event.params.destination,
eventsSummary: GLOBAL_EVENTS_SUMMARY_KEY,
Expand All @@ -66,7 +66,7 @@ FuturesMarket.FundingRecomputed.handler(async ({ event, context }) => {

const futuresMarket_FundingRecomputedEntity: FuturesMarket_FundingRecomputed =
{
id: event.transactionHash + event.logIndex.toString(),
id: event.transaction.hash + event.logIndex.toString(),
funding: event.params.funding,
index: event.params.index,
timestamp: event.params.timestamp,
Expand All @@ -91,7 +91,7 @@ FuturesMarket.FuturesTracking.handler(async ({ event, context }) => {
};

const futuresMarket_FuturesTrackingEntity: FuturesMarket_FuturesTracking = {
id: event.transactionHash + event.logIndex.toString(),
id: event.transaction.hash + event.logIndex.toString(),
trackingCode: event.params.trackingCode,
baseAsset: event.params.baseAsset,
marketKey: event.params.marketKey,
Expand Down Expand Up @@ -119,7 +119,7 @@ FuturesMarket.MarginTransferred.handler(async ({ event, context }) => {

const futuresMarket_MarginTransferredEntity: FuturesMarket_MarginTransferred =
{
id: event.transactionHash + event.logIndex.toString(),
id: event.transaction.hash + event.logIndex.toString(),
account: event.params.account,
marginDelta: event.params.marginDelta,
eventsSummary: GLOBAL_EVENTS_SUMMARY_KEY,
Expand All @@ -144,7 +144,7 @@ FuturesMarket.NextPriceOrderRemoved.handler(async ({ event, context }) => {

const futuresMarket_NextPriceOrderRemovedEntity: FuturesMarket_NextPriceOrderRemoved =
{
id: event.transactionHash + event.logIndex.toString(),
id: event.transaction.hash + event.logIndex.toString(),
account: event.params.account,
currentRoundId: event.params.currentRoundId,
sizeDelta: event.params.sizeDelta,
Expand Down Expand Up @@ -175,7 +175,7 @@ FuturesMarket.NextPriceOrderSubmitted.handler(async ({ event, context }) => {

const futuresMarket_NextPriceOrderSubmittedEntity: FuturesMarket_NextPriceOrderSubmitted =
{
id: event.transactionHash + event.logIndex.toString(),
id: event.transaction.hash + event.logIndex.toString(),
account: event.params.account,
sizeDelta: event.params.sizeDelta,
targetRoundId: event.params.targetRoundId,
Expand Down Expand Up @@ -204,7 +204,7 @@ FuturesMarket.PositionLiquidated.handler(async ({ event, context }) => {

const futuresMarket_PositionLiquidatedEntity: FuturesMarket_PositionLiquidated =
{
id: event.transactionHash + event.logIndex.toString(),
id: event.transaction.hash + event.logIndex.toString(),
event_id: event.params.id,
account: event.params.account,
liquidator: event.params.liquidator,
Expand Down Expand Up @@ -232,7 +232,7 @@ FuturesMarket.PositionModified.handler(async ({ event, context }) => {
};

const futuresMarket_PositionModifiedEntity: FuturesMarket_PositionModified = {
id: event.transactionHash + event.logIndex.toString(),
id: event.transaction.hash + event.logIndex.toString(),
event_id: event.params.id,
account: event.params.account,
margin: event.params.margin,
Expand Down Expand Up @@ -267,7 +267,7 @@ FuturesMarketManager.MarketAdded.handler(async ({ event, context }) => {

const futuresMarketManager_MarketAddedEntity: FuturesMarketManager_MarketAdded =
{
id: event.transactionHash + event.logIndex.toString(),
id: event.transaction.hash + event.logIndex.toString(),
market: event.params.market,
asset: event.params.asset,
marketKey: event.params.marketKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# yaml-language-server: $schema=../../../../cli/npm/envio/evm.schema.json
name: Uniswap # Name of the project
description: My Awesome Contract # Description of the project

field_selection:
transaction_fields:
- hash
- transaction_index
contracts:
- name: SwapContract # User-defined contract name
handler: src/EventHandler.ts # Location of the file that handles the events emitted by this contract
Expand Down
Loading

0 comments on commit f7ea343

Please sign in to comment.