Skip to content

Commit

Permalink
minimum bep2 symbol to 2
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoyangLiu committed Dec 30, 2020
1 parent 8b07877 commit 31a6551
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions contracts/TokenHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ contract TokenHub is ITokenHub, System, IParamSubscriber, IApplication, ISystemR
uint8 constant public TRANSFER_IN_FAILURE_UNKNOWN = 5;

uint256 constant public MAX_BEP2_TOTAL_SUPPLY = 9000000000000000000;
uint8 constant public MINIMUM_BEP20_SYMBOL_LEN = 3;
uint8 constant public MINIMUM_BEP20_SYMBOL_LEN = 2;
uint8 constant public MAXIMUM_BEP20_SYMBOL_LEN = 8;
uint8 constant public BEP2_TOKEN_DECIMALS = 8;
bytes32 constant public BEP2_TOKEN_SYMBOL_FOR_BNB = 0x424E420000000000000000000000000000000000000000000000000000000000; // "BNB"
Expand Down Expand Up @@ -333,7 +333,7 @@ contract TokenHub is ITokenHub, System, IParamSubscriber, IApplication, ISystemR
}
idx++;
}
return (transOutSynPkg, true);
return (transOutSynPkg, success);
}

function handleTransferOutFailAckPackage(bytes memory msgBytes) internal {
Expand Down
4 changes: 2 additions & 2 deletions contracts/TokenHub.template
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ contract TokenHub is ITokenHub, System, IParamSubscriber, IApplication, ISystemR
uint8 constant public TRANSFER_IN_FAILURE_UNKNOWN = 5;

uint256 constant public MAX_BEP2_TOTAL_SUPPLY = 9000000000000000000;
uint8 constant public MINIMUM_BEP20_SYMBOL_LEN = 3;
uint8 constant public MINIMUM_BEP20_SYMBOL_LEN = 2;
uint8 constant public MAXIMUM_BEP20_SYMBOL_LEN = 8;
uint8 constant public BEP2_TOKEN_DECIMALS = 8;
bytes32 constant public BEP2_TOKEN_SYMBOL_FOR_BNB = 0x424E420000000000000000000000000000000000000000000000000000000000; // "BNB"
Expand Down Expand Up @@ -333,7 +333,7 @@ contract TokenHub is ITokenHub, System, IParamSubscriber, IApplication, ISystemR
}
idx++;
}
return (transOutSynPkg, true);
return (transOutSynPkg, success);
}

function handleTransferOutFailAckPackage(bytes memory msgBytes) internal {
Expand Down
10 changes: 5 additions & 5 deletions contracts/TokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ contract TokenManager is System, IApplication, IParamSubscriber {
uint8 constant public SYNC_STATUS_TIMEOUT = 1;
uint8 constant public SYNC_STATUS_NOT_BOUND_MIRROR = 2;

uint8 constant public MINIMUM_BEP20_SYMBOL_LEN = 3;
uint8 constant public MINIMUM_BEP20_SYMBOL_LEN = 2;
uint8 constant public MAXIMUM_BEP20_SYMBOL_LEN = 8;

uint256 constant public TEN_DECIMALS = 1e10;
Expand Down Expand Up @@ -342,7 +342,7 @@ contract TokenManager is System, IApplication, IParamSubscriber {
require(nameBytes.length>=1 && nameBytes.length<=32, "name length must be in [1,32]");
string memory symbol = IBEP20(bep20Addr).symbol();
bytes memory symbolBytes = bytes(symbol);
require(symbolBytes.length>=MINIMUM_BEP20_SYMBOL_LEN && symbolBytes.length<=MAXIMUM_BEP20_SYMBOL_LEN, "symbol length must be in [3,8]");
require(symbolBytes.length>=MINIMUM_BEP20_SYMBOL_LEN && symbolBytes.length<=MAXIMUM_BEP20_SYMBOL_LEN, "symbol length must be in [2,8]");
for (uint8 i = 0; i < symbolBytes.length; i++) {
require((symbolBytes[i]>='A' && symbolBytes[i]<='Z') || (symbolBytes[i]>='a' && symbolBytes[i]<='z') || (symbolBytes[i]>='0' && symbolBytes[i]<='9'), "symbol should only contain alphabet and number");
}
Expand Down Expand Up @@ -393,7 +393,7 @@ contract TokenManager is System, IApplication, IParamSubscriber {
(MirrorSynPackage memory mirrorSynPackage, bool decodeSuccess) = decodeMirrorSynPackage(msgBytes);
require(decodeSuccess, "unrecognized package");
mirrorPendingRecord[mirrorSynPackage.bep20Addr] = false;
(bool success, ) = mirrorSynPackage.mirrorSender.call{gas: MAX_GAS_FOR_TRANSFER_BNB, value: mirrorSynPackage.mirrorFee*TEN_DECIMALS}("");
(bool success, ) = mirrorSynPackage.mirrorSender.call{gas: MAX_GAS_FOR_TRANSFER_BNB, value: mirrorSynPackage.mirrorFee.mul(TEN_DECIMALS)}("");
if (!success) {
address(uint160(SYSTEM_REWARD_ADDR)).transfer(mirrorSynPackage.mirrorFee.mul(TEN_DECIMALS));
}
Expand Down Expand Up @@ -493,9 +493,9 @@ contract TokenManager is System, IApplication, IParamSubscriber {
function handleSyncFailAckPackage(bytes memory msgBytes) internal {
(SyncSynPackage memory syncSynPackage, bool decodeSuccess) = decodeSyncSynPackage(msgBytes);
require(decodeSuccess, "unrecognized package");
(bool success, ) = syncSynPackage.syncSender.call{gas: MAX_GAS_FOR_TRANSFER_BNB, value: syncSynPackage.syncFee*TEN_DECIMALS}("");
(bool success, ) = syncSynPackage.syncSender.call{gas: MAX_GAS_FOR_TRANSFER_BNB, value: syncSynPackage.syncFee.mul(TEN_DECIMALS)}("");
if (!success) {
address(uint160(SYSTEM_REWARD_ADDR)).transfer(syncSynPackage.syncFee*TEN_DECIMALS);
address(uint160(SYSTEM_REWARD_ADDR)).transfer(syncSynPackage.syncFee.mul(TEN_DECIMALS));
}
}

Expand Down
4 changes: 2 additions & 2 deletions genesis.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions test/TestTokenHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -997,14 +997,14 @@ contract('TokenHub', (accounts) => {

try {
await xyzToken.setName("XYZ Token", {from: xyzTokenOwner});
await xyzToken.setSymbol("XY", {from: xyzTokenOwner});
await xyzToken.setSymbol("X", {from: xyzTokenOwner});

let timestamp = Math.floor(Date.now() / 1000); // counted by second
let expireTime = timestamp + 300; // expire at five minutes later
await tokenManager.mirror(xyzToken.address, expireTime, {from: player, value: miniRelayFee.add(mirrorFee)});
assert.fail();
} catch (error) {
assert.ok(error.toString().includes("symbol length must be in [3,8]"));
assert.ok(error.toString().includes("symbol length must be in [2,8]"));
}

try {
Expand All @@ -1016,7 +1016,7 @@ contract('TokenHub', (accounts) => {
await tokenManager.mirror(xyzToken.address, expireTime, {from: player, value: miniRelayFee.add(mirrorFee)});
assert.fail();
} catch (error) {
assert.ok(error.toString().includes("symbol length must be in [3,8]"));
assert.ok(error.toString().includes("symbol length must be in [2,8]"));
}

try {
Expand Down

0 comments on commit 31a6551

Please sign in to comment.