Skip to content

Commit

Permalink
fix: apply code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pgebal committed Dec 31, 2019
1 parent 1496f42 commit 6ba1a99
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
12 changes: 6 additions & 6 deletions plasma_framework/contracts/src/framework/ExitGameController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import "../utils/PosLib.sol";
* For details, see the Plasma MVP spec: https://ethresear.ch/t/minimal-viable-plasma/426
*/
contract ExitGameController is ExitGameRegistry {
// exit hashed (priority, token) => IExitProcessor
// exit hashed (priority, vault id, token) => IExitProcessor
mapping (bytes32 => IExitProcessor) public delegations;
// hashed (vault id, token) => PriorityQueue
mapping (bytes32 => PriorityQueue) public exitsQueues;
Expand Down Expand Up @@ -132,7 +132,7 @@ contract ExitGameController is ExitGameRegistry {

queue.insert(priority);

bytes32 delegationKey = getDelegationKey(priority, token);
bytes32 delegationKey = getDelegationKey(priority, vaultId, token);
delegations[delegationKey] = exitProcessor;

emit ExitQueued(exitId, priority);
Expand All @@ -159,7 +159,7 @@ contract ExitGameController is ExitGameRegistry {
require(topExitId == 0 || exitId == topExitId,
"Top exit ID of the queue is different to the one specified");

bytes32 delegationKey = getDelegationKey(uniquePriority, token);
bytes32 delegationKey = getDelegationKey(uniquePriority, vaultId, token);
IExitProcessor processor = delegations[delegationKey];
uint256 processedNum = 0;

Expand All @@ -175,7 +175,7 @@ contract ExitGameController is ExitGameRegistry {
}

uniquePriority = queue.getMin();
delegationKey = getDelegationKey(uniquePriority, token);
delegationKey = getDelegationKey(uniquePriority, vaultId, token);
exitId = ExitPriority.parseExitId(uniquePriority);
processor = delegations[delegationKey];
}
Expand Down Expand Up @@ -229,7 +229,7 @@ contract ExitGameController is ExitGameRegistry {
return address(exitsQueues[queueKey]) != address(0);
}

function getDelegationKey(uint256 priority, address token) private pure returns (bytes32) {
return keccak256(abi.encodePacked(priority, token));
function getDelegationKey(uint256 priority, uint256 vaultId, address token) private pure returns (bytes32) {
return keccak256(abi.encodePacked(priority, vaultId, token));
}
}
30 changes: 26 additions & 4 deletions plasma_framework/test/src/framework/ExitGameController.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ contract('ExitGameController', () => {

it('saves the exit data to map', async () => {
const priority = await this.dummyExitGame.priorityFromEnqueue();
const delegationKey = web3.utils.soliditySha3(priority, this.dummyExit.token);
const delegationKey = web3.utils.soliditySha3(priority, VAULT_ID, this.dummyExit.token);
const exitProcessor = await this.controller.delegations(delegationKey);

expect(exitProcessor).to.equal(this.dummyExit.exitProcessor);
Expand Down Expand Up @@ -321,15 +321,37 @@ contract('ExitGameController', () => {
);
});

it('should be able to process when the exitId is set to 0', async () => {
it('should process the exit when the exitId is set to 0', async () => {
const tx = await this.controller.processExits(VAULT_ID, this.dummyToken, 0, 1);
await expectEvent.inLogs(tx.logs, 'ProcessedExitsNum', {
processedNum: new BN(1),
token: this.dummyToken,
});
});

it('should be able to process when the exitId is set to the exact top of the queue', async () => {
it('should process an exit for the same token and exitId but a different vault', async () => {
const otherVaultId = VAULT_ID + 1;
await this.controller.addExitQueue(otherVaultId, this.dummyToken);

await this.dummyExitGame.enqueue(
otherVaultId,
this.dummyExit.token,
this.dummyExit.exitableAt,
this.dummyExit.txPos,
this.dummyExit.exitId,
this.dummyExit.exitProcessor,
);

await this.controller.processExits(VAULT_ID, this.dummyToken, 0, 1);

const tx = await this.controller.processExits(otherVaultId, this.dummyToken, 0, 1);
await expectEvent.inLogs(tx.logs, 'ProcessedExitsNum', {
processedNum: new BN(1),
token: this.dummyToken,
});
});

it('should process the exit when the exitId is set to the exact top of the queue', async () => {
const tx = await this.controller.processExits(
VAULT_ID, this.dummyToken, this.dummyExit.exitId, 1,
);
Expand All @@ -355,7 +377,7 @@ contract('ExitGameController', () => {

await this.controller.processExits(VAULT_ID, this.dummyToken, 0, 1);

const delegationKey = web3.utils.soliditySha3(priority, this.dummyExit.token);
const delegationKey = web3.utils.soliditySha3(priority, VAULT_ID, this.dummyExit.token);
const exitProcessor = await this.controller.delegations(delegationKey);
expect(exitProcessor).to.equal(constants.ZERO_ADDRESS);
});
Expand Down

0 comments on commit 6ba1a99

Please sign in to comment.