Skip to content

Commit

Permalink
improving tests execution for ThresholdCondition
Browse files Browse the repository at this point in the history
  • Loading branch information
aaitor committed Apr 27, 2021
1 parent d3609c2 commit f26f390
Show file tree
Hide file tree
Showing 3 changed files with 346 additions and 53 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"glob": "^7.1.4",
"mathjs": "~7.0.0",
"prettier": "^2.1.2",
"solidity-coverage": "^0.7.13",
"solidity-coverage": "^0.7.16",
"truffle-contract-size": "^2.0.1",
"solhint": "^3.2.0",
"truffle": "^5.1.56",
Expand Down
80 changes: 47 additions & 33 deletions test/unit/conditions/ThresholdCondition.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,62 @@ contract('Threshold Condition', (accounts) => {
const createRole = accounts[0]
let hashLockCondition
let randomConditionID
let epochLibrary
let conditionStoreManager
let thresholdCondition
const randomConditions = []

async function setupTest({
conditionId = constants.bytes32.one,
conditionId = testUtils.generateId(),
conditionType = constants.address.dummy,
createRole = accounts[0],
owner = accounts[1],
fulfillInputConditions = true,
includeRandomInputConditions = false,
MaxNConditions = 50
} = {}) {
const epochLibrary = await EpochLibrary.new()
await ConditionStoreManager.link('EpochLibrary', epochLibrary.address)

const conditionStoreManager = await ConditionStoreManager.new()
await conditionStoreManager.initialize(
owner,
{ from: accounts[0] }
)
if (!thresholdCondition) {
epochLibrary = await EpochLibrary.new()
await ConditionStoreManager.link('EpochLibrary', epochLibrary.address)

await conditionStoreManager.delegateCreateRole(
createRole,
{ from: owner }
)
conditionStoreManager = await ConditionStoreManager.new()
await conditionStoreManager.initialize(
owner,
{ from: accounts[0] }
)

const thresholdCondition = await ThresholdCondition.new()
await thresholdCondition.initialize(
owner,
conditionStoreManager.address,
{ from: accounts[0] }
)
await conditionStoreManager.delegateCreateRole(
createRole,
{ from: owner }
)

// create dummy and real input conditions
hashLockCondition = await HashLockCondition.new()
await hashLockCondition.initialize(
owner,
conditionStoreManager.address,
{ from: owner }
)
thresholdCondition = await ThresholdCondition.new()
await thresholdCondition.initialize(
owner,
conditionStoreManager.address,
{ from: accounts[0] }
)

// create dummy and real input conditions
hashLockCondition = await HashLockCondition.new()
await hashLockCondition.initialize(
owner,
conditionStoreManager.address,
{ from: owner }
)
}

const condition_1 = testUtils.generateId()
const condition_2 = testUtils.generateId()

const firstConditionId = await hashLockCondition.generateId(
constants.bytes32.one,
condition_1,
constants.condition.hashlock.uint.keccak
)

const secondConditionId = await hashLockCondition.generateId(
constants.bytes32.two,
condition_2,
constants.condition.hashlock.uint.keccak
)

Expand All @@ -80,12 +90,12 @@ contract('Threshold Condition', (accounts) => {

if (fulfillInputConditions) {
await hashLockCondition.fulfill(
constants.bytes32.one,
condition_1,
constants.condition.hashlock.uint.preimage
)

await hashLockCondition.fulfill(
constants.bytes32.two,
condition_2,
constants.condition.hashlock.uint.preimage
)

Expand Down Expand Up @@ -121,7 +131,9 @@ contract('Threshold Condition', (accounts) => {
createRole,
owner,
inputConditions,
randomConditions
randomConditions,
condition_1,
condition_2
}
}

Expand Down Expand Up @@ -205,7 +217,9 @@ contract('Threshold Condition', (accounts) => {
thresholdCondition,
conditionStoreManager,
inputConditions,
createRole
createRole,
condition_1,
condition_2
} = await setupTest()
const agreementId = constants.bytes32.three

Expand All @@ -230,8 +244,8 @@ contract('Threshold Condition', (accounts) => {
}
)
const invalidInputConditions = [
constants.bytes32.one,
constants.bytes32.two
condition_1,
condition_2
]
await assert.isRejected(
thresholdCondition.methods['fulfill(bytes32,bytes32[],uint256)'](
Expand Down

0 comments on commit f26f390

Please sign in to comment.