This repository has been archived by the owner on Jul 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LL-4373 Discard existing ops on sync if blacklist has changed (#1010)
* LL-4373 Discard existing ops on sync if blacklist has changed Add testing for blacklisted feature * update tests * snapshot Co-authored-by: Gaëtan Renaudeau <[email protected]>
- Loading branch information
1 parent
7bd5015
commit c51eac8
Showing
11 changed files
with
235 additions
and
8 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,95 @@ | ||
// @flow | ||
import "../../__tests__/test-helpers/setup"; | ||
import { reduce } from "rxjs/operators"; | ||
import { fromAccountRaw } from "../../account"; | ||
import { getAccountCurrency } from "../../account/helpers"; | ||
import type { Account } from "../../types"; | ||
import { getAccountBridge } from "../../bridge"; | ||
import { makeBridgeCacheSystem } from "../../bridge/cache"; | ||
import { ethereum1 } from "./test-dataset"; | ||
|
||
describe("blacklistedTokenIds functionality", () => { | ||
const account = fromAccountRaw(ethereum1); | ||
let localCache = {}; | ||
const cache = makeBridgeCacheSystem({ | ||
saveData(c, d) { | ||
localCache[c.id] = d; | ||
return Promise.resolve(); | ||
}, | ||
getData(c) { | ||
return Promise.resolve(localCache[c.id]); | ||
}, | ||
}); | ||
|
||
test("initial raw account contains no token accounts", async () => { | ||
await cache.prepareCurrency(account.currency); | ||
expect(ethereum1.subAccounts?.length).toBeFalsy(); | ||
}); | ||
|
||
test("sync finds tokens, but not blacklisted ones", async () => { | ||
const bridge = getAccountBridge(account); | ||
const blacklistedTokenIds = ["ethereum/erc20/weth"]; | ||
const synced = await bridge | ||
.sync(account, { | ||
paginationConfig: {}, | ||
blacklistedTokenIds, | ||
}) | ||
.pipe(reduce((a, f: (Account) => Account) => f(a), account)) | ||
.toPromise(); | ||
|
||
// Contains token accounts | ||
expect(synced.subAccounts?.length).toBeTruthy(); | ||
|
||
// Contains a known token | ||
expect( | ||
synced.subAccounts.find( | ||
(a) => getAccountCurrency(a)?.id === "ethereum/erc20/0x_project" | ||
) | ||
).toBeTruthy(); | ||
|
||
// Does not contain a blacklisted token | ||
expect( | ||
synced.subAccounts.find((a) => | ||
blacklistedTokenIds.includes(getAccountCurrency(a)?.id) | ||
) | ||
).toBe(undefined); | ||
}); | ||
|
||
test("account resyncs tokens if no longer blacklisted", async () => { | ||
const bridge = getAccountBridge(account); | ||
const blacklistedTokenIds = ["ethereum/erc20/weth"]; | ||
const syncedWithoutWeth = await bridge | ||
.sync(account, { | ||
paginationConfig: {}, | ||
blacklistedTokenIds, | ||
}) | ||
.pipe(reduce((a, f: (Account) => Account) => f(a), account)) | ||
.toPromise(); | ||
|
||
// Contains token accounts | ||
expect(syncedWithoutWeth.subAccounts?.length).toBeTruthy(); | ||
|
||
// Does not contain a blacklisted token | ||
expect( | ||
syncedWithoutWeth.subAccounts.find((a) => | ||
blacklistedTokenIds.includes(getAccountCurrency(a)?.id) | ||
) | ||
).toBe(undefined); | ||
|
||
//Sync again with `syncedWithoutWeth` as a base but without it being blacklisted | ||
const synced = await bridge | ||
.sync(account, { | ||
paginationConfig: {}, | ||
blacklistedTokenIds: ["ethereum/erc20/somethingElse"], | ||
}) | ||
.pipe(reduce((a, f: (Account) => Account) => f(a), account)) | ||
.toPromise(); | ||
|
||
// Does not contain a blacklisted token | ||
expect( | ||
synced.subAccounts.find( | ||
(a) => getAccountCurrency(a)?.id === "ethereum/erc20/weth" | ||
) | ||
).toBeTruthy(); | ||
}); | ||
}); |
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
c51eac8
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.
Successfully deployed to the following URLs: