-
Notifications
You must be signed in to change notification settings - Fork 74
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
test: reduce flaky tests #1266
Merged
Merged
test: reduce flaky tests #1266
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
57af1bb
test: reduce flaky tests
benjlevesque eba32e0
drop redundant
benjlevesque 944e3cb
other fixes
benjlevesque 51efe92
timeout
benjlevesque 9e69a43
timeout
benjlevesque 2420a11
fixes
benjlevesque caafdf8
remove btc usage
benjlevesque a2642ac
Update packages/payment-detection/README.md
MantisClone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { BigNumber } from 'ethers'; | ||
|
||
export default [ | ||
// etherscan | ||
{ | ||
hash: '0x0b53c5296a7b286fef52336529f3934584fea116725d1fe4c59552e926229059', | ||
type: 0, | ||
accessList: null, | ||
blockHash: '0x8535994e0a366ccfc61f5f925ce59404346569342bda1d80ccedfa6fed24c21a', | ||
blockNumber: 9082338, | ||
transactionIndex: 151, | ||
confirmations: 9581599, | ||
from: '0xc12F17Da12cd01a9CDBB216949BA0b41A6Ffc4EB', | ||
gasPrice: BigNumber.from('0x02540be400'), | ||
gasLimit: BigNumber.from('0x5288'), | ||
to: '0xc12F17Da12cd01a9CDBB216949BA0b41A6Ffc4EB', | ||
value: BigNumber.from('0x21'), | ||
nonce: 18, | ||
data: '0x9649a1a4dd5854ed', | ||
creates: null, | ||
chainId: 0, | ||
timestamp: 1575969371, | ||
}, | ||
|
||
// polygonscan | ||
{ | ||
hash: '0x50af07756eb07bb0eb29943cb7206d8359c829aef7f6dad50f61b488c2790c1c', | ||
type: 0, | ||
accessList: null, | ||
blockHash: '0x186a3f7a4a49ef302223bc72cd45a07f01a7c0c6bf1fc3127fc97de7879874f5', | ||
blockNumber: 17182533, | ||
transactionIndex: 108, | ||
confirmations: 33274506, | ||
from: '0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93', | ||
gasPrice: BigNumber.from('0x02f4d4f484'), | ||
gasLimit: BigNumber.from('0x5288'), | ||
to: '0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93', | ||
value: BigNumber.from('0x038d7ea4c68000'), | ||
nonce: 11, | ||
data: '0x5f05d421a5ed3558', | ||
creates: null, | ||
chainId: 0, | ||
timestamp: 1627050587, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
import { PaymentTypes } from '@requestnetwork/types'; | ||
import { EthInputDataInfoRetriever } from '../../src/eth/info-retriever'; | ||
import PaymentReferenceCalculator from '../../src/payment-reference-calculator'; | ||
import etherscanFixtures from './etherscan-fixtures'; | ||
import { providers } from 'ethers'; | ||
|
||
describe('api/eth/info-retriever', () => { | ||
beforeAll(() => { | ||
jest | ||
.spyOn(providers.EtherscanProvider.prototype, 'getHistory') | ||
.mockResolvedValue(etherscanFixtures as any); | ||
}); | ||
|
||
// In this test, we're looking this transaction: | ||
// https://etherscan.io/tx/0x0de1759d8b246939e370e1d0509e3ed6f1d5f4f5b79735636c0283b64ff6f5ed | ||
it('can get the balance of an address', async () => { | ||
|
@@ -11,7 +19,8 @@ describe('api/eth/info-retriever', () => { | |
'01000', | ||
'1234567890123456', | ||
paymentAddress, | ||
); // 9649a1a4dd5854ed | ||
); | ||
expect(paymentReference).toBe('9649a1a4dd5854ed'); | ||
|
||
const infoRetriever = new EthInputDataInfoRetriever( | ||
paymentAddress, | ||
|
@@ -20,20 +29,19 @@ describe('api/eth/info-retriever', () => { | |
paymentReference, | ||
); | ||
const events = await infoRetriever.getTransferEvents(); | ||
|
||
// If this assertion fails, another transaction with the data `9649a1a4dd5854ed` | ||
// has been set to the address `0xc12F17Da12cd01a9CDBB216949BA0b41A6Ffc4EB` | ||
expect(events).toHaveLength(1); | ||
|
||
expect(events[0].name).toBe('payment'); | ||
expect(events[0].amount).toBe('33'); | ||
expect(typeof events[0].timestamp).toBe('number'); | ||
expect(events[0].parameters!.txHash).toBe( | ||
'0x0b53c5296a7b286fef52336529f3934584fea116725d1fe4c59552e926229059', | ||
); | ||
expect(typeof events[0].parameters!.block).toBe('number'); | ||
expect(typeof events[0].parameters!.confirmations).toBe('number'); | ||
}, 10000); | ||
expect(events).toMatchObject([ | ||
{ | ||
amount: '33', | ||
name: 'payment', | ||
parameters: { | ||
block: 9082338, | ||
confirmations: 9581599, | ||
txHash: '0x0b53c5296a7b286fef52336529f3934584fea116725d1fe4c59552e926229059', | ||
}, | ||
timestamp: 1575969371, | ||
}, | ||
]); | ||
}); | ||
|
||
it('throws when trying to use it in local', async () => { | ||
const infoRetreiver = new EthInputDataInfoRetriever( | ||
|
@@ -45,60 +53,34 @@ describe('api/eth/info-retriever', () => { | |
await expect(infoRetreiver.getTransferEvents()).rejects.toThrowError(); | ||
}); | ||
|
||
// Utility for conditionally skipping tests | ||
const describeIf = ( | ||
condition: any, | ||
...args: [string | number | Function | jest.FunctionLike, jest.EmptyFunction] | ||
) => (condition ? describe(...args) : describe.skip(...args)); | ||
it('can detect a MATIC payment to self', async () => { | ||
// NB: The from and to are the same | ||
const paymentAddress = '0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93'; | ||
const paymentReference = PaymentReferenceCalculator.calculate( | ||
'01b809015dcda94dccfc626609b0a1d8f8e656ec787cf7f59d59d242dc9f1db0ca', | ||
'a1a2a3a4a5a6a7a8', | ||
paymentAddress, | ||
); | ||
|
||
// Skip tests if build is from external fork or API tests are disabled | ||
// External forks cannot access secret API keys | ||
describeIf(!process.env.CIRCLE_PR_NUMBER && !process.env.DISABLE_API_TESTS, 'Multichain', () => { | ||
// TODO temporary disable xDAI, CELO, Sokol, and Goerli | ||
// FIXME: API-based checks should run nightly and be mocked for CI | ||
[ | ||
'mainnet', | ||
// 'rinkeby', | ||
// 'goerli', | ||
// 'xdai', | ||
// 'sokol', | ||
'fuse', | ||
//'celo', | ||
const infoRetriever = new EthInputDataInfoRetriever( | ||
paymentAddress, | ||
PaymentTypes.EVENTS_NAMES.PAYMENT, | ||
'matic', | ||
'fantom', | ||
].forEach((network) => { | ||
it(`Can get the balance on ${network}`, async () => { | ||
const retriever = new EthInputDataInfoRetriever( | ||
'0xc12F17Da12cd01a9CDBB216949BA0b41A6Ffc4EB', | ||
PaymentTypes.EVENTS_NAMES.PAYMENT, | ||
network, | ||
'9649a1a4dd5854ed', | ||
process.env[`EXPLORER_API_KEY_${network.toUpperCase()}`], | ||
); | ||
await expect(retriever.getTransferEvents()).resolves.not.toThrow(); | ||
}); | ||
}); | ||
Comment on lines
-56
to
-80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed this test. This is covered by the first test in terms of logic. The rest isn't "unit" test, but integration, and is too flaky. This is an obsolete feature and doesn't deserve the effort imo |
||
|
||
it('can detect a MATIC payment to self', async () => { | ||
// NB: The from and to are the same | ||
const paymentAddress = '0x4E64C2d06d19D13061e62E291b2C4e9fe5679b93'; | ||
const paymentReference = PaymentReferenceCalculator.calculate( | ||
'01b809015dcda94dccfc626609b0a1d8f8e656ec787cf7f59d59d242dc9f1db0ca', | ||
'a1a2a3a4a5a6a7a8', | ||
paymentAddress, | ||
); | ||
|
||
const infoRetriever = new EthInputDataInfoRetriever( | ||
paymentAddress, | ||
PaymentTypes.EVENTS_NAMES.PAYMENT, | ||
'matic', | ||
paymentReference, | ||
process.env[`EXPLORER_API_KEY_MATIC`], | ||
); | ||
const events = await infoRetriever.getTransferEvents(); | ||
expect(events).toHaveLength(1); | ||
paymentReference, | ||
); | ||
|
||
expect(events[0].amount).toBe('1000000000000000'); | ||
}); | ||
const events = await infoRetriever.getTransferEvents(); | ||
expect(events).toMatchObject([ | ||
{ | ||
amount: '1000000000000000', | ||
name: 'payment', | ||
parameters: { | ||
block: 17182533, | ||
confirmations: 33274506, | ||
txHash: '0x50af07756eb07bb0eb29943cb7206d8359c829aef7f6dad50f61b488c2790c1c', | ||
}, | ||
timestamp: 1627050587, | ||
}, | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might just be me but I always get tripped up by the NB acronym for Nota Bene. I think "Note" would be more clear.