Skip to content

Commit

Permalink
Coverage for RFQ tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiTimesChi committed Jan 6, 2024
1 parent 9fa247b commit 032f4c0
Showing 1 changed file with 131 additions and 2 deletions.
133 changes: 131 additions & 2 deletions packages/sdk-router/src/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ describe('SynapseSDK', () => {
getTestProviderUrl(SupportedChainId.ARBITRUM)
)

const opProvider: Provider = new providers.JsonRpcProvider(
getTestProviderUrl(SupportedChainId.OPTIMISM)
)

const avaxProvider: Provider = new providers.JsonRpcProvider(
getTestProviderUrl(SupportedChainId.AVALANCHE)
)
Expand Down Expand Up @@ -815,8 +819,12 @@ describe('SynapseSDK', () => {

describe('Bridge Tx Status', () => {
const synapse = new SynapseSDK(
[SupportedChainId.ARBITRUM, SupportedChainId.ETH],
[arbProvider, ethProvider]
[
SupportedChainId.ARBITRUM,
SupportedChainId.ETH,
SupportedChainId.OPTIMISM,
],
[arbProvider, ethProvider, opProvider]
)

// https://etherscan.io/tx/0xe3f0f0c1d139c48730492c900f9978449d70c0939c654d5abbfd6b191f9c7b3d
Expand Down Expand Up @@ -855,6 +863,24 @@ describe('SynapseSDK', () => {
'0xed98b02f712c940d3b37a1aa9005a5986ecefa5cdbb4505118a22ae65d4903af',
}

// https://optimistic.etherscan.io/tx/0x1fa4c4b7a10d55e9ba833a15a1e6e57cb35cc0067190576193f7a77d4e71fbee
// https://arbiscan.io/tx/0x53a8e543bc0e3f0c1cae509e50d9435c3b62073eecf1aee7ece63c3be285db30
const rfqOpToArbTx = {
txHash:
'0x1fa4c4b7a10d55e9ba833a15a1e6e57cb35cc0067190576193f7a77d4e71fbee',
synapseTxId:
'0xd0740c9ce06c2044fab4fd8519f7f20c9768431059daad3f965f6fec8d54a6c3',
}

// https://arbiscan.io/tx/0xf0ebc85b3d83123c0d70aec1f1b5b525fa54140f5d2277154364ddede56bd69f
// https://optimistic.etherscan.io/tx/0xb96f8f3dbb886bc9eb7e3e43ba4aef863814299b71e133f8f447dba5d020a8b6
const rfqArbToOpTx = {
txHash:
'0xf0ebc85b3d83123c0d70aec1f1b5b525fa54140f5d2277154364ddede56bd69f',
synapseTxId:
'0xf6524399bb7332a55377ffcf816f396759d5c753b2fa9137d5eca2db59741b2f',
}

describe('getSynapseTxId', () => {
describe('SynapseBridge', () => {
const ethSynBridge = '0x2796317b0fF8538F253012862c06787Adfb8cEb6'
Expand Down Expand Up @@ -979,6 +1005,69 @@ describe('SynapseSDK', () => {
})
})

describe('SynapseRFQ', () => {
const arbSynRFQ = '0xA9EBFCb6DCD416FE975D5aB862717B329407f4F7'
const events = 'BridgeRequested'

it('OP -> ARB', async () => {
const synapseTxId = await synapse.getSynapseTxId(
SupportedChainId.OPTIMISM,
'SynapseRFQ',
rfqOpToArbTx.txHash
)
expect(synapseTxId).toEqual(rfqOpToArbTx.synapseTxId)
})

it('ARB -> OP', async () => {
const synapseTxId = await synapse.getSynapseTxId(
SupportedChainId.ARBITRUM,
'SynapseRFQ',
rfqArbToOpTx.txHash
)
expect(synapseTxId).toEqual(rfqArbToOpTx.synapseTxId)
})

it('Throws when given a txHash that does not exist', async () => {
// Use txHash for another chain
await expect(
synapse.getSynapseTxId(
SupportedChainId.OPTIMISM,
'SynapseRFQ',
rfqArbToOpTx.txHash
)
).rejects.toThrow('Failed to get transaction receipt')
})

it('Throws when origin tx does not refer to SynapseRFQ', async () => {
const errorMsg =
`Contract ${arbSynRFQ} in transaction ${bridgeArbToEthTx.txHash}` +
` did not emit any of the expected events: ${events}`
await expect(
synapse.getSynapseTxId(
SupportedChainId.ARBITRUM,
'SynapseRFQ',
bridgeArbToEthTx.txHash
)
).rejects.toThrow(errorMsg)
})

it('Throws when given a destination tx', async () => {
// Destination tx hash for OP -> ARB
const txHash =
'0x53a8e543bc0e3f0c1cae509e50d9435c3b62073eecf1aee7ece63c3be285db30'
const errorMsg =
`Contract ${arbSynRFQ} in transaction ${txHash}` +
` did not emit any of the expected events: ${events}`
await expect(
synapse.getSynapseTxId(
SupportedChainId.ARBITRUM,
'SynapseRFQ',
txHash
)
).rejects.toThrow(errorMsg)
})
})

it('Throws when bridge module name is invalid', async () => {
await expect(
synapse.getSynapseTxId(
Expand Down Expand Up @@ -1071,6 +1160,46 @@ describe('SynapseSDK', () => {
})
})

describe('SynapseRFQ', () => {
it('OP -> ARB', async () => {
const txStatus = await synapse.getBridgeTxStatus(
SupportedChainId.ARBITRUM,
'SynapseRFQ',
rfqOpToArbTx.synapseTxId
)
expect(txStatus).toBe(true)
})

it('ARB -> OP', async () => {
const txStatus = await synapse.getBridgeTxStatus(
SupportedChainId.OPTIMISM,
'SynapseRFQ',
rfqArbToOpTx.synapseTxId
)
expect(txStatus).toBe(true)
})

it('Returns false when unknown synapseTxId', async () => {
// Using txHash instead of synapseTxId
const txStatus = await synapse.getBridgeTxStatus(
SupportedChainId.OPTIMISM,
'SynapseRFQ',
rfqArbToOpTx.txHash
)
expect(txStatus).toBe(false)
})

it('Returns false when origin chain is used instead of destination', async () => {
// First argument should be destination chainId
const txStatus = await synapse.getBridgeTxStatus(
SupportedChainId.OPTIMISM,
'SynapseRFQ',
rfqOpToArbTx.synapseTxId
)
expect(txStatus).toBe(false)
})
})

it('Throws when bridge module name is invalid', async () => {
await expect(
synapse.getBridgeTxStatus(
Expand Down

0 comments on commit 032f4c0

Please sign in to comment.