Skip to content

Commit

Permalink
transfer relayFee to tokenHub
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoyangLiu committed Dec 17, 2020
1 parent 18580b5 commit eac7c09
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion contracts/TokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ contract TokenManager is System, IApplication, IParamSubscriber {
for (uint8 i = 0; i < symbolBytes.length; i++) {
require((symbolBytes[i]>='a' && symbolBytes[i]<='a') || (symbolBytes[i]>='A' && symbolBytes[i]<='Z'), "bep20 symbol must not contain non-alphabet");
}

address(uint160(TOKEN_HUB_ADDR)).transfer(msg.value.sub(mirrorFee));
mirrorPendingRecord[bep20Addr] = true;
bytes32 bytes32Name;
assembly {
Expand Down Expand Up @@ -456,6 +456,7 @@ contract TokenManager is System, IApplication, IParamSubscriber {
uint8 decimals = IBEP20(bep20Addr).decimals();
require(convertToBep2Amount(totalSupply, decimals) <= MAX_BEP2_TOTAL_SUPPLY, "bep20 total supply is to large");

address(uint160(TOKEN_HUB_ADDR)).transfer(msg.value.sub(syncFee));
SyncSynPackage memory syncSynPackage = SyncSynPackage({
syncSender: msg.sender,
bep20Addr: bep20Addr,
Expand Down
2 changes: 1 addition & 1 deletion genesis.json

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions test/TestTokenHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -1080,13 +1080,17 @@ contract('TokenHub', (accounts) => {
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)});
const tokenManagerBalance = await web3.eth.getBalance(tokenManager.address);
assert.equal(web3.utils.toBN(tokenManagerBalance).eq(mirrorFee), true, "wrong tokenManager balance");
await tokenManager.mirror(xyzToken.address, expireTime, {from: player, value: miniRelayFee.add(mirrorFee)});
assert.fail();
} catch (error) {
assert.ok(error.toString().includes("the bep20 token is in mirror pending status"));
const mirrorChannelSeq = await crossChain.channelReceiveSequenceMap(MIRROR_CHANNELID);
const mirrorAckPackageBytes = buildMirrorAckPackage(player, xyzToken.address, 18, "", mirrorFee, 1);
await crossChain.handlePackage(mirrorAckPackageBytes, proof, merkleHeight, mirrorChannelSeq, MIRROR_CHANNELID, {from: relayer});
const tokenManagerBalance = await web3.eth.getBalance(tokenManager.address);
assert.equal(web3.utils.toBN(tokenManagerBalance).eq(web3.utils.toBN(0)), true, "wrong tokenManager balance");
}

});
Expand Down Expand Up @@ -1126,11 +1130,16 @@ contract('TokenHub', (accounts) => {
assert.equal(web3.utils.toBN(decodedMirrorSynPackage.mirrorFee).mul(web3.utils.toBN(1e10)).eq(mirrorFee), true, "Wrong mirrorFee in mirror sync package");
assert.equal(web3.utils.hexToNumber(decodedMirrorSynPackage.bep20Decimals), xyzTokenDecimals, "Wrong decimals in mirror sync package");
assert.equal(web3.utils.toBN(decodedMirrorSynPackage.bep20Supply).eq(xyzTokenTotalSupply), true, "Wrong total supply in mirror sync package");
let tokenManagerBalance = await web3.eth.getBalance(tokenManager.address);
assert.equal(web3.utils.toBN(tokenManagerBalance).eq(mirrorFee), true, "wrong tokenManager balance");

const mirrorChannelSeq = await crossChain.channelReceiveSequenceMap(MIRROR_CHANNELID);
const mirrorAckPackageBytes = buildMirrorAckPackage(player, xyzToken.address, 18, "XYZ-123", mirrorFee, 0);
await crossChain.handlePackage(mirrorAckPackageBytes, proof, merkleHeight, mirrorChannelSeq, MIRROR_CHANNELID, {from: relayer});

tokenManagerBalance = await web3.eth.getBalance(tokenManager.address);
assert.equal(web3.utils.toBN(tokenManagerBalance).eq(web3.utils.toBN(0)), true, "wrong tokenManager balance");

const bep2Symbol = await tokenHub.getBoundBep2Symbol.call(xyzToken.address);
assert.equal(bep2Symbol, "XYZ-123", "wrong symbol");

Expand All @@ -1147,5 +1156,7 @@ contract('TokenHub', (accounts) => {
assert.equal(decodedSyncSynPackage.bep20Addr.toLowerCase(), XYZToken.address.toLowerCase(), "Wrong bep20 address in sync syn package");
assert.equal(web3.utils.toBN(decodedSyncSynPackage.bep20Supply).eq(xyzTokenNewTotalSupply), true, "Wrong total supply in sync syn package");
assert.equal(web3.utils.toBN(decodedSyncSynPackage.syncFee).mul(web3.utils.toBN(1e10)).eq(syncFee), true, "Wrong mirrorFee in sync syn package");
tokenManagerBalance = await web3.eth.getBalance(tokenManager.address);
assert.equal(web3.utils.toBN(tokenManagerBalance).eq(syncFee), true, "wrong tokenManager balance");
});
});

0 comments on commit eac7c09

Please sign in to comment.