Skip to content

Commit f7ea343

Browse files
authored
Fix integration tests (#66)
* Remove transaction fields from test query * Add transaction fields to test cases
1 parent c4324e1 commit f7ea343

File tree

8 files changed

+2033
-75
lines changed

8 files changed

+2033
-75
lines changed

codegenerator/integration_tests/tests/evm_Erc20.js

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
const assert = require("assert");
22
const { exit } = require("process");
3-
const { fetchQueryWithTestCallback } = require("./graphqlFetchWithTestCallback");
3+
const {
4+
fetchQueryWithTestCallback,
5+
} = require("./graphqlFetchWithTestCallback");
46

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

710
const pollGraphQL = async () => {
811
const rawEventsQuery = `
@@ -11,8 +14,6 @@ const pollGraphQL = async () => {
1114
event_type
1215
log_index
1316
src_address
14-
transaction_hash
15-
transaction_index
1617
block_number
1718
}
1819
}
@@ -32,45 +33,61 @@ const pollGraphQL = async () => {
3233
}
3334
`;
3435

35-
console.log("Starting erc20 tests - raw events approval event test")
36+
console.log("Starting erc20 tests - raw events approval event test");
3637
// TODO: make this use promises rather than callbacks.
3738
fetchQueryWithTestCallback(rawEventsQuery, maxRetryFailureMessage, (data) => {
3839
let shouldExitOnFailure = false;
3940
try {
4041
assert(
4142
data.raw_events_by_pk.event_type === "ERC20_Approval",
42-
"event_type should be an Approval"
43+
"event_type should be an Approval",
4344
);
4445
console.log("First erc20 test passed, running account entity test.");
4546

46-
4747
// Run the second test
48-
fetchQueryWithTestCallback(accountEntityQuery, maxRetryFailureMessage, ({ Account_by_pk: account }) => {
49-
try {
50-
assert(!!account, "account should not be null or undefined");
51-
shouldExitOnFailure = true;
48+
fetchQueryWithTestCallback(
49+
accountEntityQuery,
50+
maxRetryFailureMessage,
51+
({ Account_by_pk: account }) => {
52+
try {
53+
assert(!!account, "account should not be null or undefined");
54+
shouldExitOnFailure = true;
5255

53-
assert(account.balance > 311465476000000000000, "balance should be == 70"); // NOTE the balance shouldn't change since we own this erc20 token.
54-
assert(account.approvals.length > 0, "There should be at least one approval");
55-
assert(account.approvals[0].amount == 79228162514264337593543950335n, "The first approval amount should be 50");
56-
assert(account.approvals[0].owner_id == account.id, "The first approval owner should be the account id");
57-
assert(account.approvals[0].spender_id == "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D", "The first approval spender should be correct (from uniswap)");
58-
}
59-
catch (err) {
60-
//gotta love javascript
61-
err.shouldExitOnFailure = shouldExitOnFailure
62-
throw err;
63-
}
64-
console.log("Second test passed.");
65-
});
66-
}
67-
catch (err) {
56+
assert(
57+
account.balance > 311465476000000000000,
58+
"balance should be == 70",
59+
); // NOTE the balance shouldn't change since we own this erc20 token.
60+
assert(
61+
account.approvals.length > 0,
62+
"There should be at least one approval",
63+
);
64+
assert(
65+
account.approvals[0].amount == 79228162514264337593543950335n,
66+
"The first approval amount should be 50",
67+
);
68+
assert(
69+
account.approvals[0].owner_id == account.id,
70+
"The first approval owner should be the account id",
71+
);
72+
assert(
73+
account.approvals[0].spender_id ==
74+
"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
75+
"The first approval spender should be correct (from uniswap)",
76+
);
77+
} catch (err) {
78+
//gotta love javascript
79+
err.shouldExitOnFailure = shouldExitOnFailure;
80+
throw err;
81+
}
82+
console.log("Second test passed.");
83+
},
84+
);
85+
} catch (err) {
6886
//gotta love javascript
69-
err.shouldExitOnFailure = shouldExitOnFailure
87+
err.shouldExitOnFailure = shouldExitOnFailure;
7088
throw err;
7189
}
7290
});
7391
};
7492

7593
pollGraphQL();
76-
Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
const assert = require("assert");
2-
const { fetchQueryWithTestCallback } = require("./graphqlFetchWithTestCallback");
2+
const {
3+
fetchQueryWithTestCallback,
4+
} = require("./graphqlFetchWithTestCallback");
35

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

69
const pollGraphQL = async () => {
710
const rawEventsQuery = `
@@ -10,8 +13,6 @@ const pollGraphQL = async () => {
1013
event_type
1114
log_index
1215
src_address
13-
transaction_hash
14-
transaction_index
1516
block_number
1617
}
1718
}
@@ -34,34 +35,41 @@ const pollGraphQL = async () => {
3435
try {
3536
assert(
3637
data.raw_events_by_pk.event_type === "Greeter_NewGreeting",
37-
"event_type should be Greeter_NewGreeting"
38+
"event_type should be Greeter_NewGreeting",
39+
);
40+
console.log(
41+
"First greeter passed, running the second one for user entity",
3842
);
39-
console.log("First greeter passed, running the second one for user entity");
4043

4144
// Run the second test
42-
fetchQueryWithTestCallback(userEntityQuery, maxRetryFailureMessage, ({ User_by_pk: user }) => {
43-
try {
44-
assert(!!user, "greeting should not be null or undefined");
45-
assert(
46-
user.greetings.slice(0, 3).toString() === "gm,gn,gm paris",
47-
"First 3 greetings should be 'gm,gn,gm paris'"
48-
);
49-
assert(user.numberOfGreetings >= 3, "numberOfGreetings should be >= 3");
50-
console.log("Second test passed.");
51-
}
52-
catch (err) {
53-
//gotta love javascript
54-
err.shouldExitOnFailure = shouldExitOnFailure
55-
throw err;
56-
}
57-
});
45+
fetchQueryWithTestCallback(
46+
userEntityQuery,
47+
maxRetryFailureMessage,
48+
({ User_by_pk: user }) => {
49+
try {
50+
assert(!!user, "greeting should not be null or undefined");
51+
assert(
52+
user.greetings.slice(0, 3).toString() === "gm,gn,gm paris",
53+
"First 3 greetings should be 'gm,gn,gm paris'",
54+
);
55+
assert(
56+
user.numberOfGreetings >= 3,
57+
"numberOfGreetings should be >= 3",
58+
);
59+
console.log("Second test passed.");
60+
} catch (err) {
61+
//gotta love javascript
62+
err.shouldExitOnFailure = shouldExitOnFailure;
63+
throw err;
64+
}
65+
},
66+
);
5867
} catch (err) {
5968
//gotta love javascript
60-
err.shouldExitOnFailure = shouldExitOnFailure
69+
err.shouldExitOnFailure = shouldExitOnFailure;
6170
throw err;
6271
}
6372
});
64-
6573
};
6674

6775
pollGraphQL();

codegenerator/integration_tests/tests/test_indexers/dynamic_contracts/config-dynamic-contracts.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
# yaml-language-server: $schema=../../../../cli/npm/envio/evm.schema.json
12
name: kwenta-factory-example
3+
field_selection:
4+
transaction_fields:
5+
- hash
6+
- transaction_index
27
networks:
38
- id: 10
49
start_block: 4556306

codegenerator/integration_tests/tests/test_indexers/dynamic_contracts/src/DynamicContractHandlers.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ FuturesMarket.CacheUpdated.handler(async ({ event, context }) => {
4343
};
4444

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

6767
const futuresMarket_FundingRecomputedEntity: FuturesMarket_FundingRecomputed =
6868
{
69-
id: event.transactionHash + event.logIndex.toString(),
69+
id: event.transaction.hash + event.logIndex.toString(),
7070
funding: event.params.funding,
7171
index: event.params.index,
7272
timestamp: event.params.timestamp,
@@ -91,7 +91,7 @@ FuturesMarket.FuturesTracking.handler(async ({ event, context }) => {
9191
};
9292

9393
const futuresMarket_FuturesTrackingEntity: FuturesMarket_FuturesTracking = {
94-
id: event.transactionHash + event.logIndex.toString(),
94+
id: event.transaction.hash + event.logIndex.toString(),
9595
trackingCode: event.params.trackingCode,
9696
baseAsset: event.params.baseAsset,
9797
marketKey: event.params.marketKey,
@@ -119,7 +119,7 @@ FuturesMarket.MarginTransferred.handler(async ({ event, context }) => {
119119

120120
const futuresMarket_MarginTransferredEntity: FuturesMarket_MarginTransferred =
121121
{
122-
id: event.transactionHash + event.logIndex.toString(),
122+
id: event.transaction.hash + event.logIndex.toString(),
123123
account: event.params.account,
124124
marginDelta: event.params.marginDelta,
125125
eventsSummary: GLOBAL_EVENTS_SUMMARY_KEY,
@@ -144,7 +144,7 @@ FuturesMarket.NextPriceOrderRemoved.handler(async ({ event, context }) => {
144144

145145
const futuresMarket_NextPriceOrderRemovedEntity: FuturesMarket_NextPriceOrderRemoved =
146146
{
147-
id: event.transactionHash + event.logIndex.toString(),
147+
id: event.transaction.hash + event.logIndex.toString(),
148148
account: event.params.account,
149149
currentRoundId: event.params.currentRoundId,
150150
sizeDelta: event.params.sizeDelta,
@@ -175,7 +175,7 @@ FuturesMarket.NextPriceOrderSubmitted.handler(async ({ event, context }) => {
175175

176176
const futuresMarket_NextPriceOrderSubmittedEntity: FuturesMarket_NextPriceOrderSubmitted =
177177
{
178-
id: event.transactionHash + event.logIndex.toString(),
178+
id: event.transaction.hash + event.logIndex.toString(),
179179
account: event.params.account,
180180
sizeDelta: event.params.sizeDelta,
181181
targetRoundId: event.params.targetRoundId,
@@ -204,7 +204,7 @@ FuturesMarket.PositionLiquidated.handler(async ({ event, context }) => {
204204

205205
const futuresMarket_PositionLiquidatedEntity: FuturesMarket_PositionLiquidated =
206206
{
207-
id: event.transactionHash + event.logIndex.toString(),
207+
id: event.transaction.hash + event.logIndex.toString(),
208208
event_id: event.params.id,
209209
account: event.params.account,
210210
liquidator: event.params.liquidator,
@@ -232,7 +232,7 @@ FuturesMarket.PositionModified.handler(async ({ event, context }) => {
232232
};
233233

234234
const futuresMarket_PositionModifiedEntity: FuturesMarket_PositionModified = {
235-
id: event.transactionHash + event.logIndex.toString(),
235+
id: event.transaction.hash + event.logIndex.toString(),
236236
event_id: event.params.id,
237237
account: event.params.account,
238238
margin: event.params.margin,
@@ -267,7 +267,7 @@ FuturesMarketManager.MarketAdded.handler(async ({ event, context }) => {
267267

268268
const futuresMarketManager_MarketAddedEntity: FuturesMarketManager_MarketAdded =
269269
{
270-
id: event.transactionHash + event.logIndex.toString(),
270+
id: event.transaction.hash + event.logIndex.toString(),
271271
market: event.params.market,
272272
asset: event.params.asset,
273273
marketKey: event.params.marketKey,

codegenerator/integration_tests/tests/test_indexers/test_exits/config.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
# yaml-language-server: $schema=../../../../cli/npm/envio/evm.schema.json
12
name: Uniswap # Name of the project
23
description: My Awesome Contract # Description of the project
3-
4+
field_selection:
5+
transaction_fields:
6+
- hash
7+
- transaction_index
48
contracts:
59
- name: SwapContract # User-defined contract name
610
handler: src/EventHandler.ts # Location of the file that handles the events emitted by this contract

0 commit comments

Comments
 (0)