Skip to content

Commit 3e04c14

Browse files
author
pedro
committedJul 23, 2021
Pass the sender to the hasVoted call function
1 parent 1873ea3 commit 3e04c14

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed
 

‎federator/integrationTest/integrationTest.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,9 @@ async function transfer(originFederators, destinationFederators, config, origin,
508508
logger.info(`${destination} token balance`, balance);
509509
let destinationInitialUserBalance = balance;
510510

511-
// Cross AnotherToken (type id 0) Small Amount < toWei('0.1')
512-
const userSmallAmount = originWeb3.utils.toWei('0.0516');
513-
const userMediumAmount = originWeb3.utils.toWei('0.109');
511+
// Cross AnotherToken (type id 0) Small Amount < toWei('0.01')
512+
const userSmallAmount = originWeb3.utils.toWei('0.0056');
513+
const userMediumAmount = originWeb3.utils.toWei('0.019'); // < toWei('0.1')
514514
const userLargeAmount = originWeb3.utils.toWei('1.32');
515515
const userAppoveTotalAmount = originWeb3.utils.toWei('10');
516516

@@ -520,18 +520,18 @@ async function transfer(originFederators, destinationFederators, config, origin,
520520
await methodCall.call({from: userAddress});
521521
await transactionSender.sendTransaction(anotherTokenAddress, methodCall.encodeABI(), 0, userPrivateKey, true);
522522

523-
// Cross AnotherToken (type id 0) Small Amount < toWei('0.1')
523+
// Cross AnotherToken (type id 0) Small Amount < toWei('0.01')
524524
methodCall = bridgeContract.methods.receiveTokensTo(anotherTokenAddress, userAddress, userSmallAmount);
525525
await methodCall.call({from: userAddress});
526526
const smallAmountReceipt = await transactionSender.sendTransaction(originBridgeAddress, methodCall.encodeABI(), 0, userPrivateKey, true);
527527

528-
// Cross AnotherToken (type id 0) Medium Amount >= toWei('0.1') && < toWei('1')
528+
// Cross AnotherToken (type id 0) Medium Amount >= toWei('0.01') && < toWei('0.1')
529529
methodCall = bridgeContract.methods.receiveTokensTo(anotherTokenAddress, userAddress, userMediumAmount);
530530
await methodCall.call({from: userAddress});
531531
const mediumAmountReceipt = await transactionSender.sendTransaction(originBridgeAddress, methodCall.encodeABI(), 0, userPrivateKey, true);
532532

533-
// Cross AnotherToken (type id 0) Large Amount >= toWei('1')
534-
methodCall = bridgeContract.methods.receiveTokensTo(anotherTokenAddress, userAddress, userLargeAmount)
533+
// Cross AnotherToken (type id 0) Large Amount >= toWei('0.1')
534+
methodCall = bridgeContract.methods.receiveTokensTo(anotherTokenAddress, userAddress, userLargeAmount)
535535
await methodCall.call({from: userAddress});
536536
const largeAmountReceipt = await transactionSender.sendTransaction(originBridgeAddress, methodCall.encodeABI(), 0, userPrivateKey, true);
537537

‎federator/src/lib/Federator.js

+22-20
Original file line numberDiff line numberDiff line change
@@ -168,26 +168,28 @@ module.exports = class Federator {
168168
_typeId: typeId
169169
} = log.returnValues;
170170

171-
let {
172-
allowed,
171+
const mainBridge = await this.bridgeFactory.getMainBridgeContract();
172+
const sideTokenAddress = await utils.retry3Times(mainBridge.getMappedToken(tokenAddress).call);
173+
let allowed,
173174
mediumAmount,
174175
largeAmount
175-
} = await allowTokens.getLimits(tokenAddress);
176-
177-
if (!allowed) {
178-
const mainBridge = await this.bridgeFactory.getMainBridgeContract();
179-
const sideTokenAddress = await utils.retry3Times(mainBridge.getMappedToken(tokenAddress).call);
180-
if (sideTokenAddress == utils.zeroAddress) {
176+
if (sideTokenAddress == utils.zeroAddress) {
177+
({
178+
allowed,
179+
mediumAmount,
180+
largeAmount
181+
} = await allowTokens.getLimits(tokenAddress));
182+
if (!allowed) {
181183
throw new Error(`Original Token not allowed nor side token Tx:${transactionHash} originalTokenAddress:${tokenAddress}`);
182-
} else {
183-
({
184-
allowed,
185-
mediumAmount,
186-
largeAmount
187-
} = await allowTokens.getLimits(sideTokenAddress));
188-
if (!allowed) {
189-
this.logger.error(`Side token:${sideTokenAddress} needs to be allowed Tx:${transactionHash} originalTokenAddress:${tokenAddress}`);
190-
}
184+
}
185+
} else {
186+
({
187+
allowed,
188+
mediumAmount,
189+
largeAmount
190+
} = await allowTokens.getLimits(sideTokenAddress));
191+
if (!allowed) {
192+
this.logger.error(`Side token:${sideTokenAddress} needs to be allowed Tx:${transactionHash} originalTokenAddress:${tokenAddress}`);
191193
}
192194
}
193195

@@ -196,7 +198,7 @@ module.exports = class Federator {
196198
const largeAmountBN = new BN(largeAmount);
197199
const amountBN = new BN(amount);
198200

199-
if(mediumAndSmall) {
201+
if (mediumAndSmall) {
200202
// At this point we're processing blocks newer than largeAmountConfirmations
201203
// and older than smallAmountConfirmations
202204
if(amountBN.gte(largeAmountBN)) {
@@ -232,7 +234,7 @@ module.exports = class Federator {
232234

233235
let wasProcessed = await utils.retry3Times(fedContract.transactionWasProcessed(transactionId).call);
234236
if (!wasProcessed) {
235-
let hasVoted = await utils.retry3Times(fedContract.hasVoted(transactionId).call);
237+
let hasVoted = await fedContract.hasVoted(transactionId).call({ from });
236238
if(!hasVoted) {
237239
this.logger.info(`Voting tx: ${log.transactionHash} block: ${log.blockHash} originalTokenAddress: ${tokenAddress}`);
238240
await this._voteTransaction(
@@ -310,7 +312,7 @@ module.exports = class Federator {
310312
}
311313

312314
const receipt = await this.transactionSender.sendTransaction(fedContract.getAddress(), txData, 0, this.config.privateKey);
313-
315+
314316
if(receipt.status == false) {
315317
fs.writeFileSync(
316318
this.revertedTxnsPath,

0 commit comments

Comments
 (0)