Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Fixes problems with ERC20 data and add tests so it no longer happen
Browse files Browse the repository at this point in the history
  • Loading branch information
gre committed Aug 30, 2019
1 parent b8bf5c5 commit 9ff916d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@ledgerhq/compressjs": "1.3.2",
"@ledgerhq/errors": "4.68.4",
"@ledgerhq/hw-app-btc": "4.68.4",
"@ledgerhq/hw-app-eth": "4.68.4",
"@ledgerhq/hw-app-eth": "4.69.1",
"@ledgerhq/hw-app-xrp": "4.68.4",
"@ledgerhq/hw-transport": "4.68.4",
"@ledgerhq/hw-transport-mocker": "4.68.4",
Expand Down Expand Up @@ -85,7 +85,7 @@
"eslint-plugin-flowtype": "^4.2.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"flow-bin": "^0.106.2",
"flow-bin": "^0.106.3",
"flow-copy-source": "^2.0.8",
"flow-typed": "^2.6.1",
"glob": "^7.1.4",
Expand Down
20 changes: 19 additions & 1 deletion scripts/crypto-assets-importer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ axios
? countervaluesTickers.includes(a[2])
: true)
);
const contractGroup = {};
all.forEach(a => {
const matches = all.filter(b => a[6] === b[6]);
if (matches.length > 1 && !contractGroup[a[6]]) {
contractGroup[a[6]] = matches;
}
});
const groups = {};
all.forEach(a => {
if (a[7]) return;
Expand All @@ -58,6 +65,17 @@ axios
(WARN_IF_COUNTERVALUES ? countervaluesTickers.includes(a) : true)
);

if (Object.keys(contractGroup).length > 0) {
console.warn("\nERC20 THAT HAVE SAME CONTRACT ADDRESSES:\n");
Object.keys(contractGroup).forEach(key => {
console.warn(
key +
" contract used in erc20: " +
contractGroup[key].map(a => a[2]).join(", ")
);
});
}

if (fiatCollisions.length > 0) {
console.warn("\nERC20 THAT COLLIDES WITH FIAT TICKERS:\n");
fiatCollisions.forEach(t => {
Expand Down Expand Up @@ -85,7 +103,7 @@ axios
});
}

return all;
return all.filter(a => !contractGroup[a[6]]);
})
.then(all =>
fs.writeFileSync(output, imp.outputTemplate(all), "utf-8")
Expand Down
17 changes: 17 additions & 0 deletions src/__tests__/helpers/currencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
sanitizeValueString,
findTokenByTicker
} from "../../currencies";
import { byContractAddress } from "@ledgerhq/hw-app-eth/erc20";

import "../../load/tokens/ethereum/erc20";

Expand Down Expand Up @@ -88,6 +89,22 @@ test("fiats list elements are correct", () => {
}
});

test("erc20 are all consistant with those on ledgerjs side", () => {
for (const token of listTokens()) {
if (token.tokenType === "erc20") {
const tokenData = byContractAddress(token.contractAddress);
if (!tokenData) {
throw new Error(token.name + " not available in ledgerjs data");
}
expect(token.ticker.toLowerCase()).toBe(tokenData.ticker.toLowerCase());
expect(token.contractAddress.toLowerCase()).toBe(
tokenData.contractAddress.toLowerCase()
);
expect(token.units[0].magnitude).toBe(tokenData.decimals);
}
}
});

test("tokens are correct", () => {
expect(listTokens().length).toBeGreaterThan(0);
for (const token of listTokens()) {
Expand Down
4 changes: 0 additions & 4 deletions src/load/tokens/ethereum/erc20.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,10 @@
"@ledgerhq/hw-transport" "^4.68.4"
create-hash "^1.1.3"

"@ledgerhq/hw-app-eth@4.68.4":
version "4.68.4"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-app-eth/-/hw-app-eth-4.68.4.tgz#90e606ffc85872063313ac6c19b4b64f7d00c9bf"
integrity sha512-fLy04GNAZOdtut0j5bf6BvByLtxqefckqpABmXM84wo6Ae579EjIbMrOdJ+ojigVlHIu1nXFzZbxzSwci+I9cA==
"@ledgerhq/hw-app-eth@4.69.1":
version "4.69.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-app-eth/-/hw-app-eth-4.69.1.tgz#1a8d54240c6d40892f975f88206c06d59b8efc89"
integrity sha512-aFKLN+N4eGMZJX14acOjjpKM4BVHipKpG11tt57m8Ra7pW+CkOomm5BVixRJrjHozIX1XlJ1wNtlenzWtBlKww==
dependencies:
"@ledgerhq/errors" "^4.68.4"
"@ledgerhq/hw-transport" "^4.68.4"
Expand Down Expand Up @@ -3440,10 +3440,10 @@ flatted@^2.0.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.0.tgz#55122b6536ea496b4b44893ee2608141d10d9916"
integrity sha512-R+H8IZclI8AAkSBRQJLVOsxwAoHd6WC40b4QTNWIjzAa6BXOBfQcM587MXDTVPeYaopFNWHUFLx7eNmHDSxMWg==

flow-bin@^0.106.2:
version "0.106.2"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.106.2.tgz#624db7c04b00879ac14853434817c7bc5e1419db"
integrity sha512-pALWFKf+AQiX4VfSEdxruj2bSMigsrAcg8djV6Hue2y3FJyiA/Z42UkEv6zEvSIpDj1EL+cRBvJNUx6L2+gdTQ==
flow-bin@^0.106.3:
version "0.106.3"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.106.3.tgz#87b5647bc23ae0efceabb6c50490c02a8478960c"
integrity sha512-QDwmhsMmiASmwgr6r2WTz9RPsN0pb84PY0whz0JqFaBX7/Fx2wj2MOtjbR2yv+qWZnozP9U40Jd9LLt8rC3WSQ==

flow-copy-source@^2.0.8:
version "2.0.8"
Expand Down

0 comments on commit 9ff916d

Please sign in to comment.