[internal] Wanchain uses special reverse checksum format (#3216)

* ReverseCase

* Wanchain uses special reverse checksum format.

* Fix existing 6 wanchain assets, revert checksum format.

Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
Adam R 2020-08-10 16:56:02 +02:00 committed by GitHub
parent 483c966277
commit cbe4ef90e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 68 additions and 18 deletions

View File

@ -1,8 +1,8 @@
[
"0x0F2E7c0e904A525a24ff6F658053F6Ba5cE7a209",
"0x350BB91c9c8eF4E8c0E19FBDC6a90a24BCB1Ec2a",
"0x3beb80170272F07Aca12987af86a59888255a807",
"0x51316966907EF568689775066E97C46A4fFDE1A4",
"0xa13A41A2349d09c1e3A0Dd4D9448aF4Ad799Fc4a",
"0xC6F4465A6a521124C8e3096B62575c157999D361"
"0x0f2e7C0E904a525A24FF6f658053f6bA5Ce7A209",
"0x350bb91C9C8Ef4e8C0e19fbdc6A90A24bcb1eC2A",
"0x3BEB80170272f07aCA12987AF86A59888255A807",
"0x51316966907ef568689775066e97c46a4Ffde1a4",
"0xA13a41a2349D09C1E3a0dD4d9448Af4aD799fC4A",
"0xc6f4465a6A521124c8E3096b62575C157999d361"
]

View File

@ -40,8 +40,8 @@ async function formatInfos() {
})
}
function checkAddressChecksum(assetsFolderPath: string, address: string) {
const checksumAddress = toChecksum(address);
function checkAddressChecksum(assetsFolderPath: string, address: string, chain: string) {
const checksumAddress = toChecksum(address, chain);
if (checksumAddress !== address) {
gitMove(assetsFolderPath, address, checksumAddress);
console.log(`Renamed to checksum format ${checksumAddress}`);
@ -60,7 +60,7 @@ async function checkAddressChecksums() {
gitMove(getChainAssetPath(chain, address), file, logoFullName);
}
});
checkAddressChecksum(assetsPath, address);
checkAddressChecksum(assetsPath, address, chain);
});
});
}
@ -84,7 +84,7 @@ export class EthForks implements ActionInterface {
if (!isPathExistsSync(assetPath)) {
error += `Expect directory at path: ${assetPath}\n`;
}
const inChecksum = toChecksum(address);
const inChecksum = toChecksum(address, chain);
if (address !== inChecksum) {
error += `Expect asset at path ${assetPath} in checksum: '${inChecksum}'\n`;
}

View File

@ -1,6 +1,31 @@
import { reverseCase } from "./types";
const Web3 = require('web3');
const web3 = new Web3('ws://localhost:8546');
export const isChecksum = (address: string): boolean => web3.utils.checkAddressChecksum(address);
export const toChecksum = (address: string): string => web3.utils.toChecksumAddress(address);
export const isChecksumEthereum = (address: string): boolean => web3.utils.checkAddressChecksum(address);
export const toChecksumEthereum = (address: string): string => web3.utils.toChecksumAddress(address);
export function toChecksum(address: string, chain: string = "ethereum"): string {
var checksumEthereum = toChecksumEthereum(address);
// special handling for Wanchain
if (chain.toLowerCase() === "wanchain") {
const checksumWanchain = reverseCase(checksumEthereum).replace("X", "x");
return checksumWanchain;
}
return checksumEthereum;
}
export function isChecksum(address: string, chain: string = "ethereum"): boolean {
// special handling for Wanchain
if (chain.toLowerCase() === "wanchain") {
const addressEthereum = reverseCase(address).replace("X", "x");
return isChecksumEthereum(addressEthereum);
}
return isChecksumEthereum(address);
}

View File

@ -76,3 +76,19 @@ export function arrayEqual(a1: any[], a2: any[]): boolean {
}
return true;
}
export function reverseCase(s: string): string {
const n = s.length;
var out: string = "";
for (var i = 0; i < n; ++i) {
const c = s[i];
if (isLowerCase(c)) {
out += c.toUpperCase();
} else if (isUpperCase(s[i])) {
out += c.toLowerCase();
} else {
out += c;
}
}
return out;
}

View File

@ -18,19 +18,24 @@ import {
makeUnique,
arrayDiff,
arrayDiffNocase,
arrayEqual
arrayEqual,
reverseCase
} from "../script/common/types";
import { findImagesToFetch } from "../script/action/binance";
describe("Test eth-web3 helpers", () => {
test(`Test isChecksum`, () => {
expect(isChecksum("0x7Bb09bC8aDE747178e95B1D035ecBeEBbB18cFee"), `checksum`).toBe(true);
expect(isChecksum("0x7bb09bc8ade747178e95b1d035ecbeebbb18cfee"), `lowercase`).toBe(false);
expect(isChecksum("0x7Bb09bC8aDE747178e95B1D035ecBe"), `too short`).toBe(false);
expect(isChecksum("0x7Bb09bC8aDE747178e95B1D035ecBeEBbB18cFee", "ethereum"), `checksum`).toBe(true);
expect(isChecksum("0x7bb09bc8ade747178e95b1d035ecbeebbb18cfee", "ethereum"), `lowercase`).toBe(false);
expect(isChecksum("0x7Bb09bC8aDE747178e95B1D035ecBe", "ethereum"), `too short`).toBe(false);
expect(isChecksum("0x7Bb09bC8aDE747178e95B1D035ecBeEBbB18cFee", "wanchain"), `wanchain wrong checksum`).toBe(false);
expect(isChecksum("0x7bb09bc8ade747178e95b1d035ecbeebbb18cfee", "wanchain"), `wanchain lowercase`).toBe(false);
expect(isChecksum("0x7bB09Bc8Ade747178E95b1d035ECbEebBb18CfEE", "wanchain"), `wanchain checksum`).toBe(true);
});
test(`Test toChecksum`, () => {
expect(toChecksum("0x7bb09bc8ade747178e95b1d035ecbeebbb18cfee"), `from lowercase`).toEqual("0x7Bb09bC8aDE747178e95B1D035ecBeEBbB18cFee");
expect(toChecksum("0x7Bb09bC8aDE747178e95B1D035ecBeEBbB18cFee"), `from checksum`).toEqual("0x7Bb09bC8aDE747178e95B1D035ecBeEBbB18cFee");
expect(toChecksum("0x7bb09bc8ade747178e95b1d035ecbeebbb18cfee", "ethereum"), `from lowercase`).toEqual("0x7Bb09bC8aDE747178e95B1D035ecBeEBbB18cFee");
expect(toChecksum("0x7Bb09bC8aDE747178e95B1D035ecBeEBbB18cFee", "ethereum"), `from checksum`).toEqual("0x7Bb09bC8aDE747178e95B1D035ecBeEBbB18cFee");
expect(toChecksum("0x7bb09bc8ade747178e95b1d035ecbeebbb18cfee", "wanchain"), `wanchain, from lowercase`).toEqual("0x7bB09Bc8Ade747178E95b1d035ECbEebBb18CfEE");
});
});
@ -106,6 +111,10 @@ describe("Test type helpers", () => {
expect(arrayEqual(["a", "b", "c"], ["a", "b", "b"]), `length mismatch`).toBe(false);
expect(arrayEqual(["a", "b", "b"], ["a", "b", "c"]), `length mismatch`).toBe(false);
});
test(`Test reverseCase`, () => {
expect(reverseCase("abCDef12+-"), `mixed`).toEqual("ABcdEF12+-");
expect(reverseCase("ABcdEF12+-"), `mixed`).toEqual("abCDef12+-");
});
});
describe("Test action binance", () => {