Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
remove abort
Browse files Browse the repository at this point in the history
  • Loading branch information
shun-tak committed Apr 5, 2020
1 parent 3ff3707 commit 675ff22
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 280 deletions.
31 changes: 1 addition & 30 deletions atomic-swap-ethereum-env/contracts/Settlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ contract Settlement is Ownable {
enum SwapStatus {
Nonexistent,
Locked,
Unlocked,
Aborted
Unlocked
}

struct SwapDetail {
Expand All @@ -35,12 +34,6 @@ contract Settlement is Ownable {
bytes encodedSwapDetail
);

event Aborted(
uint256 settlementId,
string swapId,
bytes encodedSwapDetail
);

constructor(address _cordaNotary) public {
cordaNotary = _cordaNotary;
settlementId = 1;
Expand Down Expand Up @@ -98,26 +91,4 @@ contract Settlement is Ownable {
encodedSwapDetail
);
}

function abort(
string memory _swapId
) public onlyCordaNotary {
SwapDetail storage swapDetail = swapIdToDetailMap[_swapId];

require(swapDetail.status != SwapStatus.Nonexistent, "swapDetail does not exist");
require(swapDetail.status == SwapStatus.Locked, "swapDetail.status is not Locked");

// Try sending wei to targetAddress.
require(swapDetail.transferFromAddress.send(swapDetail.weiAmount));

swapDetail.status = SwapStatus.Aborted;

bytes memory encodedSwapDetail = abi.encode(swapDetail);

emit Aborted(
settlementId++,
_swapId,
encodedSwapDetail
);
}
}
106 changes: 0 additions & 106 deletions atomic-swap-ethereum-env/test/Settlement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,111 +160,5 @@ contract('Settlement', accounts => {
'swapDetail.status is not Locked',
);
});

it('cannot unlock if the swapId status is Aborted', async () => {
await this.settlement.abort(
swapId,
{ from: notaryAddress },
);

await truffleAssert.reverts(
this.settlement.unlock(
swapId,
{ from: notaryAddress },
),
'swapDetail.status is not Locked',
);
});
});

describe('abort', () => {
beforeEach(async () => {
await this.settlement.lock(
swapId,
proposerAddress,
acceptorAddress,
weiAmount,
securityAmount,
{ from: proposerAddress, value: weiAmount },
);
});

it('emits Aborted event', async () => {
const tx = await this.settlement.abort(
swapId,
{ from: notaryAddress },
);
const eventName = tx.logs[0].event;
expect(eventName).to.equal('Aborted');
const args = tx.logs[0].args;
expect(args.swapId).to.equal(swapId);

const actual = await this.settlement.swapIdToDetailMap.call(swapId);
const decodedSwapDetail = web3.eth.abi.decodeParameter({
SwapDetail: {
transferFromAddress: 'address',
transferToAddress: 'address',
weiAmount: 'uint256',
securityAmount: 'uint256',
status: 'uint8',
},
}, args.encodedSwapDetail);

expect(decodedSwapDetail.transferFromAddress).to.equal(actual.transferFromAddress);
expect(decodedSwapDetail.transferToAddress).to.equal(actual.transferToAddress);
expect(decodedSwapDetail.weiAmount).to.be.bignumber.equal(actual.weiAmount);
expect(decodedSwapDetail.securityAmount).to.be.bignumber.equal(actual.securityAmount);
expect(decodedSwapDetail.status).to.be.bignumber.equal(actual.status);
});

it('cannot execute unless it is from corda notary', async () => {
await truffleAssert.reverts(
this.settlement.abort(
swapId,
{ from: proposerAddress },
),
'caller is not the corda notary',
);
});

it('cannot unlock nonexistent swapId', async () => {
await truffleAssert.reverts(
this.settlement.unlock(
'BAD_SWAPID',
{ from: notaryAddress },
),
'swapDetail does not exist',
);
});

it('cannot abort if the swapId status is Unlocked', async () => {
await this.settlement.unlock(
swapId,
{ from: notaryAddress },
);

await truffleAssert.reverts(
this.settlement.abort(
swapId,
{ from: notaryAddress },
),
'swapDetail.status is not Locked',
);
});

it('cannot abort if the swapId status is Aborted', async () => {
await this.settlement.abort(
swapId,
{ from: notaryAddress },
);

await truffleAssert.reverts(
this.settlement.abort(
swapId,
{ from: notaryAddress },
),
'swapDetail.status is not Locked',
);
});
});
});
9 changes: 0 additions & 9 deletions cross-chain-atomic-swap-cordapp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,3 @@ xxxxxxxx-xxxx-xxxx-xx Event Watch xxxxxxxxxxxxxxxxxxxx Event Watched. (fromBl
```
xxxxxxxx-xxxx-xxxx-xx Event Watch xxxxxxxxxxxxxxxxxxxx SettleAtomicSwapFlow has executed with xxxx securities.
```

### Abort Proposal State
Run AbortAtomicSwapFlow from Proposer(ParticipantA) with ProposalState's linearId:

```
flow start jp.co.layerx.cordage.crosschainatomicswap.flow.AbortAtomicSwapFlow proposalLinearId: "1f77abf7-e209-42e6-8327-a2279c85aab7"
```

The Notary will unlock Ether to ParticipantA's Ethereum address.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ open class ProposalContract: Contract {

interface ProposalCommands : CommandData {
class Propose : ProposalCommands
class Abort : ProposalCommands
class Consume : ProposalCommands
}

Expand All @@ -37,18 +36,6 @@ open class ProposalContract: Contract {
"Both proposer and acceptor together only may sign Proposal issue transaction." using
(proposalCommand.signers.toSet() == proposal.participants.map { it.owningKey }.toSet())
}
is ProposalCommands.Abort -> requireThat {
"An Proposal Abort transaction should only consume one input state." using (tx.inputs.size == 1)
"Output state should be only one state." using (tx.outputs.size == 1)
val input = tx.inputsOfType<ProposalState>().single()
val output = tx.outputsOfType<ProposalState>().single()
"Input State's status must be PROPOSED." using (input.status == ProposalStatus.PROPOSED)
"Only the status property may change." using (output == input.withNewStatus(ProposalStatus.ABORTED))
// Abort Tx must have proposer's signature.
val expectedSigners = (input.participants).map { it.owningKey } - input.acceptor.owningKey
"The proposer only must sign an Proposal abort transaction" using
(proposalCommand.signers.toSet() == expectedSigners.toSet())
}
is ProposalCommands.Consume -> requireThat {
"An Security TransferForSettle transaction should only consume two input state." using (tx.inputs.size == 2)
"An Security TransferForSettle transaction should only create two output state." using (tx.outputs.size == 2)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,5 @@ class CustomValidatingNotaryFlow(otherSide: FlowSession, service: CustomValidati
progressTracker.currentStep = SEND_TRANSACTION_TO_ETHEREUM_CONTRACT
settlement.unlock(swapId).send()
}

if (proposalCommands.single().value is ProposalContract.ProposalCommands.Abort) {
progressTracker.currentStep = SEND_TRANSACTION_TO_ETHEREUM_CONTRACT
settlement.abort(swapId).send()
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.web3j.abi.datatypes.generated.Uint8

@CordaSerializable
enum class ProposalStatus {
NONEXISTENT, PROPOSED, CONSUMED, ABORTED;
NONEXISTENT, PROPOSED, CONSUMED;

companion object {
fun fromInt(index: Uint8): ProposalStatus {
Expand Down

0 comments on commit 675ff22

Please sign in to comment.