diff --git a/contracts/OpenSTUtility.sol b/contracts/OpenSTUtility.sol index 007d124a..e7092394 100644 --- a/contracts/OpenSTUtility.sol +++ b/contracts/OpenSTUtility.sol @@ -71,11 +71,15 @@ contract OpenSTUtility is Hasher, OpsManaged { address _staker, address _beneficiary, uint256 _amountST, uint256 _amountUT, uint256 _expirationHeight); event ProcessedMint(bytes32 indexed _uuid, bytes32 indexed _stakingIntentHash, address _token, address _staker, address _beneficiary, uint256 _amount); + event RevertedMint(bytes32 indexed _uuid, bytes32 indexed _stakingIntentHash, address _staker, + address _beneficiary, uint256 _amountUT); event RedemptionIntentDeclared(bytes32 indexed _uuid, bytes32 indexed _redemptionIntentHash, address _token, address _redeemer, uint256 _nonce, uint256 _amount, uint256 _unlockHeight, uint256 _chainIdValue); event ProcessedRedemption(bytes32 indexed _uuid, bytes32 indexed _redemptionIntentHash, address _token, address _redeemer, uint256 _amount); + event RevertedRedemption(bytes32 indexed _uuid, bytes32 indexed _redemptionIntentHash, + address _redeemer, uint256 _amountUT); /* * Constants @@ -393,6 +397,36 @@ contract OpenSTUtility is Hasher, OpsManaged { return tokenAddress; } + function revertMinting( + bytes32 _stakingIntentHash) + external + returns ( + bytes32 uuid, + address staker, + address beneficiary, + uint256 amount) + { + require(_stakingIntentHash != ""); + + Mint storage mint = mints[_stakingIntentHash]; + + // require that the mint has expired and that the staker has not + // processed the minting, ie mint has not been deleted + require(mint.expirationHeight > 0); + require(mint.expirationHeight <= block.number); + + uuid = mint.uuid; + amount = mint.amount; + staker = mint.staker; + beneficiary = mint.beneficiary; + + delete mints[_stakingIntentHash]; + + RevertedMint(uuid, _stakingIntentHash, staker, beneficiary, amount); + + return (uuid, staker, beneficiary, amount); + } + /// @dev redeemer must set an allowance for the branded token with OpenSTUtility /// as the spender so that the branded token can be taken into escrow by OpenSTUtility /// note: for STPrime, call OpenSTUtility.redeemSTPrime as a payable function @@ -514,6 +548,43 @@ contract OpenSTUtility is Hasher, OpsManaged { return tokenAddress; } + function revertRedemption( + bytes32 _redemptionIntentHash) + external + returns ( + bytes32 uuid, + address redeemer, + uint256 amountUT) + { + require(_redemptionIntentHash != ""); + + Redemption storage redemption = redemptions[_redemptionIntentHash]; + + // require that the redemption is unlocked and exists + require(redemption.unlockHeight > 0); + require(redemption.unlockHeight <= block.number); + + uuid = redemption.uuid; + amountUT = redemption.amountUT; + redeemer = redemption.redeemer; + + if (redemption.uuid == uuidSTPrime) { + // transfer throws if insufficient funds + redeemer.transfer(amountUT); + } else { + EIP20Interface token = EIP20Interface(registeredTokens[redemption.uuid].token); + + require(token.transfer(redemption.redeemer, redemption.amountUT)); + } + + delete redemptions[_redemptionIntentHash]; + + // fire event + RevertedRedemption(uuid, _redemptionIntentHash, redeemer, amountUT); + + return (uuid, redeemer, amountUT); + } + /* * Public view functions */ @@ -530,64 +601,4 @@ contract OpenSTUtility is Hasher, OpsManaged { address(registeredToken.token), registeredToken.registrar); } - - /* - * Operation functions - */ - /// @dev TODO: add events to trigger for each action - function addNameReservation( - bytes32 _hashName, - address _requester) - public - onlyAdminOrOps - returns (bool /* success */) - { - address requester = nameReservation[_hashName]; - if (requester == _requester) return true; - if (requester == address(0)) { - nameReservation[_hashName] = _requester; - return true; - } - return false; - } - - function setSymbolRoute( - bytes32 _hashSymbol, - address _token) - public - onlyAdminOrOps - returns (bool /* success */) - { - address token = symbolRoute[_hashSymbol]; - if (token == _token) return true; - if (token == address(0)) { - symbolRoute[_hashSymbol] = _token; - return true; - } - return false; - } - - function removeNameReservation( - bytes32 _hashName) - public - onlyAdminOrOps - returns (bool /* success */) - { - require(nameReservation[_hashName] != address(0)); - - delete nameReservation[_hashName]; - return true; - } - - function removeSymbolRoute( - bytes32 _hashSymbol) - public - onlyAdminOrOps - returns (bool /* success */) - { - require(symbolRoute[_hashSymbol] != address(0)); - - delete symbolRoute[_hashSymbol]; - return true; - } } \ No newline at end of file diff --git a/contracts/OpenSTValue.sol b/contracts/OpenSTValue.sol index f2c47a8a..6aa90c54 100644 --- a/contracts/OpenSTValue.sol +++ b/contracts/OpenSTValue.sol @@ -47,10 +47,14 @@ contract OpenSTValue is OpsManaged, Hasher { uint256 _chainIdUtility); event ProcessedStake(bytes32 indexed _uuid, bytes32 indexed _stakingIntentHash, address _stake, address _staker, uint256 _amountST, uint256 _amountUT); + event RevertedStake(bytes32 indexed _uuid, bytes32 indexed _stakingIntentHash, + address _staker, uint256 _amountST, uint256 _amountUT); event RedemptionIntentConfirmed(bytes32 indexed _uuid, bytes32 _redemptionIntentHash, address _redeemer, uint256 _amountST, uint256 _amountUT, uint256 _expirationHeight); event ProcessedUnstake(bytes32 indexed _uuid, bytes32 indexed _redemptionIntentHash, address stake, address _redeemer, uint256 _amountST); + event RevertedUnstake(bytes32 indexed _uuid, bytes32 indexed _redemptionIntentHash, + address _redeemer, uint256 _amountST); /* * Constants @@ -238,6 +242,38 @@ contract OpenSTValue is OpsManaged, Hasher { return stakeAddress; } + function revertStaking( + bytes32 _stakingIntentHash) + external + returns ( + bytes32 uuid, + uint256 amountST, + address staker) + { + require(_stakingIntentHash != ""); + + Stake storage stake = stakes[_stakingIntentHash]; + + // require that the stake is unlocked and exists + require(stake.unlockHeight > 0); + require(stake.unlockHeight <= block.number); + + assert(valueToken.balanceOf(address(this)) >= stake.amountST); + // revert the amount that was intended to be staked back to staker + require(valueToken.transfer(stake.staker, stake.amountST)); + + uuid = stake.uuid; + amountST = stake.amountST; + staker = stake.staker; + + RevertedStake(stake.uuid, _stakingIntentHash, stake.staker, + stake.amountST, stake.amountUT); + + delete stakes[_stakingIntentHash]; + + return (uuid, amountST, staker); + } + function confirmRedemptionIntent( bytes32 _uuid, address _redeemer, @@ -324,6 +360,35 @@ contract OpenSTValue is OpsManaged, Hasher { return stakeAddress; } + function revertUnstaking( + bytes32 _redemptionIntentHash) + external + onlyRegistrar + returns ( + bytes32 uuid, + address redeemer, + uint256 amountST) + { + require(_redemptionIntentHash != ""); + + Unstake storage unstake = unstakes[_redemptionIntentHash]; + + // require that the unstake has expired and that the redeemer has not + // processed the unstaking, ie unstake has not been deleted + require(unstake.expirationHeight > 0); + require(unstake.expirationHeight <= block.number); + + uuid = unstake.uuid; + redeemer = unstake.redeemer; + amountST = unstake.amountST; + + delete unstakes[_redemptionIntentHash]; + + RevertedUnstake(uuid, _redemptionIntentHash, redeemer, amountST); + + return (uuid, redeemer, amountST); + } + /* * Public view functions */ diff --git a/test/OpenSTUtility.js b/test/OpenSTUtility.js index 20b32eb3..97f53199 100644 --- a/test/OpenSTUtility.js +++ b/test/OpenSTUtility.js @@ -472,113 +472,4 @@ contract('OpenSTUtility', function(accounts) { }) }) }) - -/** - * note: code is removed from contracts as unused and space needed for protocol completion - TODO: remove once certain no such logic is required - - describe('AddNameReservation', async () => { - before(async () => { - contracts = await OpenSTUtility_utils.deployOpenSTUtility(artifacts, accounts); - openSTUtility = contracts.openSTUtility; - await openSTUtility.setAdminAddress(accounts[2]); - }) - - it('fails to add by non-adminOrOps', async () => { - await Utils.expectThrow(openSTUtility.addNameReservation(hashName, requester)); - }) - - it('successfully adds', async () => { - assert.equal(await openSTUtility.nameReservation.call(hashName), 0); - assert.equal(await openSTUtility.addNameReservation.call(hashName, requester, { from: accounts[2] }), true); - await openSTUtility.addNameReservation(hashName, requester, { from: accounts[2] }); - - assert.equal(await openSTUtility.nameReservation.call(hashName), requester); - }) - - it('fails to add if exists with a different requester', async () => { - await openSTUtility.addNameReservation.call(hashName, accounts[0], { from: accounts[2] }); - - assert.notEqual(await openSTUtility.nameReservation.call(hashName), accounts[0]); - assert.equal(await openSTUtility.nameReservation.call(hashName), requester); - }) - }) - - describe('SetSymbolRoute', async () => { - before(async () => { - contracts = await OpenSTUtility_utils.deployOpenSTUtility(artifacts, accounts); - openSTUtility = contracts.openSTUtility; - await openSTUtility.setAdminAddress(accounts[2]); - }) - - it('fails to set by non-adminOrOps', async () => { - await Utils.expectThrow(openSTUtility.setSymbolRoute(hashSymbol, token)); - }) - - it('successfully sets', async () => { - assert.equal(await openSTUtility.symbolRoute.call(hashSymbol), 0); - assert.equal(await openSTUtility.setSymbolRoute.call(hashSymbol, token, { from: accounts[2] }), true); - await openSTUtility.setSymbolRoute(hashSymbol, token, { from: accounts[2] }); - - assert.equal(await openSTUtility.symbolRoute.call(hashSymbol), token); - }) - - it('fails to set if exists with a different token', async () => { - await openSTUtility.setSymbolRoute.call(hashSymbol, accounts[0], { from: accounts[2] }); - - assert.notEqual(await openSTUtility.symbolRoute.call(hashSymbol), accounts[0]); - assert.equal(await openSTUtility.symbolRoute.call(hashSymbol), token); - }) - }) - - describe('RemoveNameReservation', async () => { - before(async () => { - contracts = await OpenSTUtility_utils.deployOpenSTUtility(artifacts, accounts); - openSTUtility = contracts.openSTUtility; - await openSTUtility.setAdminAddress(accounts[2]); - await openSTUtility.addNameReservation(hashName, requester, { from: accounts[2] }); - }) - - it('fails to remove by non-adminOrOps', async () => { - await Utils.expectThrow(openSTUtility.removeNameReservation(hashName)); - }) - - it('successfully removes', async () => { - assert.equal(await openSTUtility.nameReservation.call(hashName), requester); - assert.equal(await openSTUtility.removeNameReservation.call(hashName, { from: accounts[2] }), true); - await openSTUtility.removeNameReservation(hashName, { from: accounts[2] }) - - assert.equal(await openSTUtility.nameReservation.call(hashName), 0); - }) - - it('fails to remove if it does not exist', async () => { - await Utils.expectThrow(openSTUtility.removeNameReservation(hashName, { from: accounts[2] })); - }) - }) - - describe('removeSymbolRoute', async () => { - before(async () => { - contracts = await OpenSTUtility_utils.deployOpenSTUtility(artifacts, accounts); - openSTUtility = contracts.openSTUtility; - await openSTUtility.setAdminAddress(accounts[2]); - await openSTUtility.setSymbolRoute(hashSymbol, token, { from: accounts[2] }); - }) - - it('fails to remove by non-adminOrOps', async () => { - await Utils.expectThrow(openSTUtility.removeSymbolRoute(hashSymbol)); - }) - - it('successfully removes', async () => { - assert.equal(await openSTUtility.symbolRoute.call(hashSymbol), token); - assert.equal(await openSTUtility.removeSymbolRoute.call(hashSymbol, { from: accounts[2] }), true); - await openSTUtility.removeSymbolRoute(hashSymbol, { from: accounts[2] }) - - assert.equal(await openSTUtility.symbolRoute.call(hashSymbol), 0); - }) - - it('fails to remove if it does not exist', async () => { - await Utils.expectThrow(openSTUtility.removeSymbolRoute(hashSymbol, { from: accounts[2] })); - }) - }) -*/ }) diff --git a/test/OpenSTValue_utils.js b/test/OpenSTValue_utils.js index 53cb7be2..a9782ae4 100644 --- a/test/OpenSTValue_utils.js +++ b/test/OpenSTValue_utils.js @@ -118,6 +118,7 @@ module.exports.checkStakingIntentDeclaredEvent = (event, _uuid, _staker, _staker assert.equal(event.args._chainIdUtility, _chainIdUtility); } + module.exports.checkStakingIntentDeclaredEventProtocol = (formattedDecodedEvents, _uuid, _staker, _stakerNonce, _beneficiary, _amountST, _amountUT, _chainIdUtility) => { diff --git a/test/Protocol.js b/test/Protocol.js index 22631de2..3fe9023f 100644 --- a/test/Protocol.js +++ b/test/Protocol.js @@ -69,7 +69,6 @@ contract('OpenST', function(accounts) { describe('Setup Utility chain with Simple Token Prime', function () { - var simpleToken = null; var registrarVC = null; var registrarUC = null; @@ -77,10 +76,9 @@ contract('OpenST', function(accounts) { var openSTValue = null; var openSTUtility = null; var stPrime = null; - var brandedToken = null var stpContractAddress = null; - var simpleStakeContractAddress = null; + var simpleStakeContractAddress = null; var registeredBrandedTokenUuid = null; var registeredBrandedToken = null; var nonceBT = null; @@ -204,10 +202,9 @@ contract('OpenST', function(accounts) { registeredBrandedTokenUuid = eventLog.args._uuid; registeredBrandedToken = eventLog.args._token; - brandedToken = BrandedToken.at(registeredBrandedToken); - - utils.logResponse(result, "OpenSTUtility.proposeBrandedToken"); + brandedToken = BrandedToken.at(registeredBrandedToken); + utils.logResponse(result, "OpenSTUtility.proposeBrandedToken"); }); // register Branded Token on Utility Chain @@ -222,8 +219,7 @@ contract('OpenST', function(accounts) { openSTUtilityUtils.checkRegisteredBrandedTokenEventOnProtocol(formattedDecodedEvents, registrarUC.address, registeredBrandedToken, registeredBrandedTokenUuid, symbol, name, conversionRate, requester); - utils.logResponse(result, "OpenSTUtility.registerBrandedToken"); - + utils.logResponse(result, "OpenSTUtility.registerBrandedToken"); }); // register Utility Token on Value Chain @@ -238,97 +234,98 @@ contract('OpenST', function(accounts) { openSTValueUtils.checkUtilityTokenRegisteredEventOnProtocol(formattedDecodedEvents, registeredBrandedTokenUuid, symbol, name, 18, conversionRate, CHAINID_UTILITY, requester); - var event = formattedDecodedEvents['UtilityTokenRegistered']; + var event = formattedDecodedEvents['UtilityTokenRegistered']; - simpleStakeContractAddress = event.stake; + simpleStakeContractAddress = event.stake; - utils.logResponse(result, "OpenSTValue.registerUtilityToken"); + utils.logResponse(result, "OpenSTValue.registerUtilityToken"); }); - it("report gas usage: register and propose branded token", async () => { - utils.printGasStatistics(); - utils.clearReceipts(); - }); + it("report gas usage: register and propose branded token", async () => { + utils.printGasStatistics(); + utils.clearReceipts(); + }); }); // stake ST for BT context('stake Simple Token for Branded Token', function() { - it("approve and stake Simple Token", async() => { - // transfer ST to requester account - Assert.ok(await simpleToken.transfer(requester, AMOUNT_ST, { from: deployMachine })); - // Check for requester simpleToken Balance - var balanceOfRequester = await simpleToken.balanceOf(requester); - Assert.equal(balanceOfRequester, AMOUNT_ST.toNumber()); - // requester sets allowance for OpenSTValue - Assert.ok(await simpleToken.approve(openSTValue.address, AMOUNT_ST, { from: requester })); + it("approve and stake Simple Token", async() => { + // transfer ST to requester account + Assert.ok(await simpleToken.transfer(requester, AMOUNT_ST, { from: deployMachine })); + // Check for requester simpleToken Balance + var balanceOfRequester = await simpleToken.balanceOf(requester); + Assert.equal(balanceOfRequester, AMOUNT_ST.toNumber()); + // requester sets allowance for OpenSTValue + Assert.ok(await simpleToken.approve(openSTValue.address, AMOUNT_ST, { from: requester })); - // Query nonceBT in advance - nonceBT = await openSTValue.getNextNonce.call(requester); - Assert.equal(nonceBT, 1); - // requester calls OpenSTValue.stake to initiate the staking for Branded Token with registeredBrandedTokenUuid - // with requester as the beneficiary - var stakeResult = await openSTValue.stake(registeredBrandedTokenUuid, AMOUNT_ST, requester, { from: requester }); + // Query nonceBT in advance + nonceBT = await openSTValue.getNextNonce.call(requester); + Assert.equal(nonceBT, 1); + // requester calls OpenSTValue.stake to initiate the staking for Branded Token with registeredBrandedTokenUuid + // with requester as the beneficiary + var stakeResult = await openSTValue.stake(registeredBrandedTokenUuid, AMOUNT_ST, requester, { from: requester }); - openSTValueUtils.checkStakingIntentDeclaredEventProtocol(stakeResult.logs[0], registeredBrandedTokenUuid, requester, nonceBT, - requester, AMOUNT_ST, AMOUNT_BT, CHAINID_UTILITY); + openSTValueUtils.checkStakingIntentDeclaredEventProtocol(stakeResult.logs[0], registeredBrandedTokenUuid, requester, nonceBT, + requester, AMOUNT_ST, AMOUNT_BT, CHAINID_UTILITY); - stakingIntentHash = stakeResult.logs[0].args._stakingIntentHash; - unlockHeight = stakeResult.logs[0].args._unlockHeight; - nonceBT = stakeResult.logs[0].args._stakerNonce; + stakingIntentHash = stakeResult.logs[0].args._stakingIntentHash; + unlockHeight = stakeResult.logs[0].args._unlockHeight; + nonceBT = stakeResult.logs[0].args._stakerNonce; - utils.logResponse(stakeResult, "OpenSTUtility.approveAndStake"); + utils.logResponse(stakeResult, "OpenSTUtility.approveAndStake"); }); - it("confirm staking intent for Branded Token", async() => { + it("confirm staking intent for Branded Token", async() => { - const result = await registrarUC.confirmStakingIntent(openSTUtility.address, registeredBrandedTokenUuid, - requester, nonceBT, requester, AMOUNT_ST, AMOUNT_BT, unlockHeight, stakingIntentHash, { from: intercommUC }); + const result = await registrarUC.confirmStakingIntent(openSTUtility.address, registeredBrandedTokenUuid, + requester, nonceBT, requester, AMOUNT_ST, AMOUNT_BT, unlockHeight, stakingIntentHash, { from: intercommUC }); - var formattedDecodedEvents = web3EventsDecoder.perform(result.receipt, openSTUtility.address, openSTUtilityArtifacts.abi); + var formattedDecodedEvents = web3EventsDecoder.perform(result.receipt, openSTUtility.address, openSTUtilityArtifacts.abi); - openSTUtilityUtils.checkStakingIntentConfirmedEventOnProtocol(formattedDecodedEvents, registeredBrandedTokenUuid, - stakingIntentHash, requester, requester, AMOUNT_ST, AMOUNT_BT); + openSTUtilityUtils.checkStakingIntentConfirmedEventOnProtocol(formattedDecodedEvents, registeredBrandedTokenUuid, + stakingIntentHash, requester, requester, AMOUNT_ST, AMOUNT_BT); - utils.logResponse(result, "OpenSTUtility.confirmStakingIntent"); + utils.logResponse(result, "OpenSTUtility.confirmStakingIntent"); - }); + }); - it("process staking", async() => { - const result = await openSTValue.processStaking(stakingIntentHash, { from: requester }); + it("process staking", async() => { + const result = await openSTValue.processStaking(stakingIntentHash, { from: requester }); - openSTValueUtils.checkProcessedStakeEvent(result.logs[0], registeredBrandedTokenUuid, stakingIntentHash, - simpleStakeContractAddress, requester, AMOUNT_ST, AMOUNT_BT); + openSTValueUtils.checkProcessedStakeEvent(result.logs[0], registeredBrandedTokenUuid, stakingIntentHash, + simpleStakeContractAddress, requester, AMOUNT_ST, AMOUNT_BT); - utils.logResponse(result, "OpenSTValue.processStaking"); + utils.logResponse(result, "OpenSTValue.processStaking"); - }); + }); - it("process minting", async() => { - const result = await openSTUtility.processMinting(stakingIntentHash, { from: requester }); + it("process minting", async() => { - openSTUtilityUtils.checkProcessedMintEvent(result.logs[0], registeredBrandedTokenUuid, stakingIntentHash, - registeredBrandedToken, requester, requester, AMOUNT_BT); + const result = await openSTUtility.processMinting(stakingIntentHash, { from: requester }); - utils.logResponse(result, "OpenSTValue.processminting"); - }); + openSTUtilityUtils.checkProcessedMintEvent(result.logs[0], registeredBrandedTokenUuid, stakingIntentHash, + registeredBrandedToken, requester, requester, AMOUNT_BT); - it("claim Branded Token", async() => { - var balanceBefore = await brandedToken.balanceOf(requester); - const o = await brandedToken.claim(requester, { from: intercommUC }); - var balanceAfter = await brandedToken.balanceOf(requester); - var totalSupply = await brandedToken.totalSupply.call(); - Assert.equal(totalSupply.toNumber(), AMOUNT_BT.toNumber()); - Assert.equal(balanceAfter.sub(balanceBefore).toNumber(), AMOUNT_BT.toNumber()); - }); + utils.logResponse(result, "OpenSTValue.processminting"); + }); - it("report gas usage: stake Simple Token for Branded Token", async () => { - utils.printGasStatistics(); - utils.clearReceipts(); - }); + it("claim Branded Token", async() => { + var balanceBefore = await brandedToken.balanceOf(requester); + const o = await brandedToken.claim(requester, { from: intercommUC }); + var balanceAfter = await brandedToken.balanceOf(requester); + var totalSupply = await brandedToken.totalSupply.call(); + Assert.equal(totalSupply.toNumber(), AMOUNT_BT.toNumber()); + Assert.equal(balanceAfter.sub(balanceBefore).toNumber(), AMOUNT_BT.toNumber()); + }); + + it("report gas usage: stake Simple Token for Branded Token", async () => { + utils.printGasStatistics(); + utils.clearReceipts(); + }); }); @@ -366,117 +363,117 @@ contract('OpenST', function(accounts) { // unstake BT by Redeemer context('Redeem and Unstake Branded Token', function() { - it("approve branded token", async() => { + it("approve branded token", async() => { - var approveResult = await brandedToken.approve(openSTUtility.address, REDEEM_AMOUNT_BT, { from: redeemer }) - Assert.ok(approveResult); - utils.logResponse(approveResult, "OpenSTUtility.approveResult"); + var approveResult = await brandedToken.approve(openSTUtility.address, REDEEM_AMOUNT_BT, { from: redeemer }) + Assert.ok(approveResult); + utils.logResponse(approveResult, "OpenSTUtility.approveResult"); - }); + }); - it("call redeem", async() => { + it("call redeem", async() => { - nonce = await openSTValue.getNextNonce.call(redeemer); - var redeemResult = await openSTUtility.redeem(registeredBrandedTokenUuid, REDEEM_AMOUNT_BT, nonce, { from: redeemer }); - redemptionIntentHash = redeemResult.logs[0].args._redemptionIntentHash; - unlockHeight = redeemResult.logs[0].args._unlockHeight; - openSTUtilityUtils.checkRedemptionIntentDeclaredEvent(redeemResult.logs[0], registeredBrandedTokenUuid, redemptionIntentHash, brandedToken.address, - redeemer, nonce, REDEEM_AMOUNT_BT, unlockHeight, CHAINID_VALUE); - utils.logResponse(redeemResult, "OpenSTUtility.redeem"); + nonce = await openSTValue.getNextNonce.call(redeemer); + var redeemResult = await openSTUtility.redeem(registeredBrandedTokenUuid, REDEEM_AMOUNT_BT, nonce, { from: redeemer }); + redemptionIntentHash = redeemResult.logs[0].args._redemptionIntentHash; + unlockHeight = redeemResult.logs[0].args._unlockHeight; + openSTUtilityUtils.checkRedemptionIntentDeclaredEvent(redeemResult.logs[0], registeredBrandedTokenUuid, redemptionIntentHash, brandedToken.address, + redeemer, nonce, REDEEM_AMOUNT_BT, unlockHeight, CHAINID_VALUE); + utils.logResponse(redeemResult, "OpenSTUtility.redeem"); - }); + }); - it("confirm redemption intent", async() => { + it("confirm redemption intent", async() => { - var confirmRedemptionResult = await registrarVC.confirmRedemptionIntent( openSTValue.address, registeredBrandedTokenUuid, - redeemer, nonce, REDEEM_AMOUNT_BT, unlockHeight, redemptionIntentHash, { from: intercommVC }); + var confirmRedemptionResult = await registrarVC.confirmRedemptionIntent( openSTValue.address, registeredBrandedTokenUuid, + redeemer, nonce, REDEEM_AMOUNT_BT, unlockHeight, redemptionIntentHash, { from: intercommVC }); - var formattedDecodedEvents = web3EventsDecoder.perform(confirmRedemptionResult.receipt, openSTValue.address, openSTValueArtifacts.abi); - var redeemedAmountST = (REDEEM_AMOUNT_BT/conversionRate); - openSTValueUtils.checkRedemptionIntentConfirmedEventOnProtocol(formattedDecodedEvents, registeredBrandedTokenUuid, - redemptionIntentHash, redeemer, redeemedAmountST, REDEEM_AMOUNT_BT); + var formattedDecodedEvents = web3EventsDecoder.perform(confirmRedemptionResult.receipt, openSTValue.address, openSTValueArtifacts.abi); + var redeemedAmountST = (REDEEM_AMOUNT_BT/conversionRate); + openSTValueUtils.checkRedemptionIntentConfirmedEventOnProtocol(formattedDecodedEvents, registeredBrandedTokenUuid, + redemptionIntentHash, redeemer, redeemedAmountST, REDEEM_AMOUNT_BT); - utils.logResponse(confirmRedemptionResult, "OpenSTValue.confirmRedemptionIntent"); + utils.logResponse(confirmRedemptionResult, "OpenSTValue.confirmRedemptionIntent"); - }); + }); - it("process redemption", async() => { + it("process redemption", async() => { - var processRedeemingResult = await openSTUtility.processRedeeming(redemptionIntentHash, { from: redeemer }); + var processRedeemingResult = await openSTUtility.processRedeeming(redemptionIntentHash, { from: redeemer }); - utils.logResponse(processRedeemingResult, "openSTUtility.processRedeeming"); + utils.logResponse(processRedeemingResult, "openSTUtility.processRedeeming"); - }); + }); - it("process unstake", async() => { + it("process unstake", async() => { - var processUnstakeResult = await openSTValue.processUnstaking(redemptionIntentHash, { from: redeemer }); + var processUnstakeResult = await openSTValue.processUnstaking(redemptionIntentHash, { from: redeemer }); - utils.logResponse(processUnstakeResult, "openSTValue.processUnstaking"); + utils.logResponse(processUnstakeResult, "openSTValue.processUnstaking"); - }); + }); - it("report gas usage: Redeem and Unstake Branded Token", async () => { + it("report gas usage: Redeem and Unstake Branded Token", async () => { - utils.printGasStatistics(); - utils.clearReceipts(); + utils.printGasStatistics(); + utils.clearReceipts(); - }); + }); }); // unstake STPrime by Redeemer context('Redeem and Unstake STPrime', function() { - it("call redeem", async() => { + it("call redeem", async() => { - nonce = await openSTValue.getNextNonce.call(redeemer); - var redeemResult = await openSTUtility.redeemSTPrime(nonce, { from: redeemer, value: REDEEM_AMOUNT_STPRIME }); - redemptionIntentHash = redeemResult.logs[0].args._redemptionIntentHash; - unlockHeight = redeemResult.logs[0].args._unlockHeight; - openSTUtilityUtils.checkRedemptionIntentDeclaredEvent(redeemResult.logs[0], uuidSTP, redemptionIntentHash, stPrime.address, - redeemer, nonce, REDEEM_AMOUNT_STPRIME, unlockHeight, CHAINID_VALUE); + nonce = await openSTValue.getNextNonce.call(redeemer); + var redeemResult = await openSTUtility.redeemSTPrime(nonce, { from: redeemer, value: REDEEM_AMOUNT_STPRIME }); + redemptionIntentHash = redeemResult.logs[0].args._redemptionIntentHash; + unlockHeight = redeemResult.logs[0].args._unlockHeight; + openSTUtilityUtils.checkRedemptionIntentDeclaredEvent(redeemResult.logs[0], uuidSTP, redemptionIntentHash, stPrime.address, + redeemer, nonce, REDEEM_AMOUNT_STPRIME, unlockHeight, CHAINID_VALUE); - utils.logResponse(redeemResult, "OpenSTUtility.STPrime.redeem"); + utils.logResponse(redeemResult, "OpenSTUtility.STPrime.redeem"); - }); + }); - it("confirm redemption intent", async() => { + it("confirm redemption intent", async() => { - var confirmRedemptionResult = await registrarVC.confirmRedemptionIntent( openSTValue.address, uuidSTP, redeemer, nonce, - REDEEM_AMOUNT_STPRIME, unlockHeight, redemptionIntentHash, { from: intercommVC }); + var confirmRedemptionResult = await registrarVC.confirmRedemptionIntent( openSTValue.address, uuidSTP, redeemer, nonce, + REDEEM_AMOUNT_STPRIME, unlockHeight, redemptionIntentHash, { from: intercommVC }); - var formattedDecodedEvents = web3EventsDecoder.perform(confirmRedemptionResult.receipt, - openSTValue.address, openSTValueArtifacts.abi); - openSTValueUtils.checkRedemptionIntentConfirmedEventOnProtocol(formattedDecodedEvents, uuidSTP, - redemptionIntentHash, redeemer, REDEEM_AMOUNT_STPRIME, REDEEM_AMOUNT_STPRIME); + var formattedDecodedEvents = web3EventsDecoder.perform(confirmRedemptionResult.receipt, + openSTValue.address, openSTValueArtifacts.abi); + openSTValueUtils.checkRedemptionIntentConfirmedEventOnProtocol(formattedDecodedEvents, uuidSTP, + redemptionIntentHash, redeemer, REDEEM_AMOUNT_STPRIME, REDEEM_AMOUNT_STPRIME); - utils.logResponse(confirmRedemptionResult, "OpenSTValue.STPrime.confirmRedemptionIntent"); + utils.logResponse(confirmRedemptionResult, "OpenSTValue.STPrime.confirmRedemptionIntent"); - }); + }); - it("process redemption", async() => { + it("process redemption", async() => { - var processRedeemingResult = await openSTUtility.processRedeeming(redemptionIntentHash, { from: redeemer }); + var processRedeemingResult = await openSTUtility.processRedeeming(redemptionIntentHash, { from: redeemer }); - utils.logResponse(processRedeemingResult, "openSTUtility.STPrime.processRedeeming"); + utils.logResponse(processRedeemingResult, "openSTUtility.STPrime.processRedeeming"); - }); + }); - it("process unstake", async() => { + it("process unstake", async() => { - var processUnstakeResult = await openSTValue.processUnstaking(redemptionIntentHash, { from: redeemer }); - utils.logResponse(processUnstakeResult, "openSTValue.STPrime.processUnstaking"); + var processUnstakeResult = await openSTValue.processUnstaking(redemptionIntentHash, { from: redeemer }); + utils.logResponse(processUnstakeResult, "openSTValue.STPrime.processUnstaking"); - }); + }); - it("report gas usage: Redeem and Unstake Simple Token Prime", async () => { + it("report gas usage: Redeem and Unstake Simple Token Prime", async () => { - utils.printGasStatistics(); - utils.clearReceipts(); + utils.printGasStatistics(); + utils.clearReceipts(); - }); + }); });