Skip to content

Commit

Permalink
Fix + tests for reinitialization
Browse files Browse the repository at this point in the history
  • Loading branch information
kosecki123 committed Apr 23, 2018
1 parent 3e4961a commit 3dadbb8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 4 additions & 0 deletions contracts/TransactionRequestCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ contract TransactionRequestCore is TransactionRequestInterface {
using RequestScheduleLib for RequestScheduleLib.ExecutionWindow;

RequestLib.Request txnRequest;
bool private initialized = false;

/*
* addressArgs[0] - meta.createdBy
Expand Down Expand Up @@ -36,7 +37,10 @@ contract TransactionRequestCore is TransactionRequestInterface {
)
public payable
{
require(!initialized);

txnRequest.initialize(addressArgs, uintArgs, callData);
initialized = true;
}

/*
Expand Down
42 changes: 40 additions & 2 deletions test/request-factory-tests/requestFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contract("Request factory", async (accounts) => {
endowment = transactionRequest.endowment,
properties,
to = accounts[2]
}) => {
} = {}) => {
const paramsForValidation = await createValidationParams(properties)
const isValid = await requestLib.validate(
[accounts[0], accounts[0], accounts[1], to],
Expand Down Expand Up @@ -178,7 +178,6 @@ contract("Request factory", async (accounts) => {
// Lastly, we just make sure that the transaction request
// address is a known request for the factory.
expect(await requestFactory.isKnownRequest(NULL_ADDR)).to.be.false // sanity check

expect(await requestFactory.isKnownRequest(txRequest.address)).to.be.true
})

Expand Down Expand Up @@ -236,4 +235,43 @@ contract("Request factory", async (accounts) => {
expect(isValid[5]).to.be.false
isValid.slice(0, 5).forEach(bool => expect(bool).to.be.true)
})

it("should not allow to reinitialize the scheduled transaction", async () => {
const { paramsForValidation } = await validate()

const params = paramsForValidation
params.push(transactionRequest.gasPrice)
params.push(transactionRequest.requiredDeposit)

// Create a request with the same args we validated
const createTx = await requestFactory.createRequest(
[
accounts[0],
accounts[1], // fee recipient
accounts[2], // to
],
params,
transactionRequest.testCallData
)

const logRequestCreated = createTx.logs.find(e => e.event === "RequestCreated")
const txRequest = await TransactionRequestCore.at(logRequestCreated.args.request)

let requestData = await parseRequestData(txRequest)
expect(requestData.txData.toAddress).to.equal(accounts[2])

await txRequest.initialize(
[
accounts[0],
accounts[0],
accounts[1], // fee recipient
accounts[3], // hijacking recipient
],
params,
transactionRequest.testCallData
).should.be.rejectedWith("VM Exception while processing transaction: revert")

requestData = await parseRequestData(txRequest)
expect(requestData.txData.toAddress).to.equal(accounts[2])
})
})

0 comments on commit 3dadbb8

Please sign in to comment.