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
Add testing for blacklisted feature
- Loading branch information
1 parent
f805b4f
commit 3c34f4a
Showing
5 changed files
with
118 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// @flow | ||
import { reduce } from "rxjs/operators"; | ||
import { setSupportedCurrencies } from "../../currencies"; | ||
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"; | ||
|
||
setSupportedCurrencies(["ethereum"]); | ||
|
||
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