Skip to content

Commit

Permalink
adding coverage ...
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsmkl committed May 24, 2022
1 parent 4a31f6c commit 403d2a6
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 35 deletions.
99 changes: 98 additions & 1 deletion test/int/nft/NFT721_e2e.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const deployConditions = require('../../helpers/deployConditions.js')

contract('End to End NFT721 Scenarios', (accounts) => {
const royalties = 10 // 10% of royalties in the secondary market
const cappedAmount = 5
const didSeed = testUtils.generateId()
const didSeed2 = testUtils.generateId()
let did
let agreementId
const checksum = testUtils.generateId()
Expand Down Expand Up @@ -142,7 +144,8 @@ contract('End to End NFT721 Scenarios', (accounts) => {
getBalance = async (a, b) => getTokenBalance(a, b, checkpoint)

return {
didRegistry
didRegistry,
nft
}
}

Expand Down Expand Up @@ -352,6 +355,8 @@ contract('End to End NFT721 Scenarios', (accounts) => {
(await conditionStoreManager.getConditionState(conditionIds[1])).toNumber(),
constants.condition.state.fulfilled
)

assert(await accessCondition.checkPermissions(collector1, nftAccessAgreement.did))
})
})

Expand Down Expand Up @@ -469,4 +474,96 @@ contract('End to End NFT721 Scenarios', (accounts) => {

runTests()
})

describe('As market I want to be able to transfer nfts and release rewards on behalf of the artist', () => {
let nftSalesAgreement
let conditionIds
it('Artist registers a new artwork and tokenize (via NFT)', async () => {
const { didRegistry, nft } = await setupTest()

did = await didRegistry.hashDID(didSeed2, artist)

await didRegistry.registerMintableDID721(
didSeed2, checksum, [], url, royalties, false, constants.activities.GENERATED, '', { from: artist })
await didRegistry.mint721(did, { from: artist })
await nft.setApprovalForAll(transferCondition.address, true, { from: artist })

assert.strictEqual(artist, await nft.ownerOf(did))
})

it('Collector sets an agreement for buying a NFT', async () => {
const data = await prepareNFTSaleAgreement({
did: did,
agreementId: agreementId,
_seller: artist,
_buyer: collector1
})
nftSalesAgreement = data.nftSalesAgreement
conditionIds = data.conditionIds
agreementId = data.agreementId

// The Collector creates an agreement on-chain for purchasing a specific NFT attached to a DID
const result = await nftSalesTemplate.createAgreement(...Object.values(nftSalesAgreement))

testUtils.assertEmitted(result, 1, 'AgreementCreated')
})

it('Collector locks the payment', async () => {
await token.mint(collector1, nftPrice, { from: owner })
await token.approve(lockPaymentCondition.address, nftPrice, { from: collector1 })
await token.approve(escrowCondition.address, nftPrice, { from: collector1 })

await lockPaymentCondition.fulfill(agreementId, did, escrowCondition.address, token.address, amounts, receivers, { from: collector1 })

const { state } = await conditionStoreManager.getCondition(conditionIds[0])
assert.strictEqual(state.toNumber(), constants.condition.state.fulfilled)
const collector1Balance = await getBalance(token, collector1)
assert.strictEqual(collector1Balance, 0)
})

it('The market can check the payment and can transfer the NFT to the collector', async () => {
assert.strictEqual(artist, await nft.ownerOf(did))

await nft.setApprovalForAll(market, true, { from: artist })
await transferCondition.fulfillForDelegate(
agreementId,
did,
artist,
collector1,
numberNFTs,
conditionIds[0],
true,
{ from: market }
)

const { state } = await conditionStoreManager.getCondition(conditionIds[1])
assert.strictEqual(state.toNumber(), constants.condition.state.fulfilled)

assert.strictEqual(collector1, await nft.ownerOf(did))
})

it('The market can release the payment to the artist', async () => {
await escrowCondition.fulfill(
agreementId,
did,
amounts,
receivers,
collector1,
escrowCondition.address,
token.address,
conditionIds[0],
conditionIds[1],
{ from: market })

const { state } = await conditionStoreManager.getCondition(conditionIds[2])
assert.strictEqual(state.toNumber(), constants.condition.state.fulfilled)

assert.strictEqual(await getBalance(token, collector1), 0)
assert.strictEqual(await getBalance(token, lockPaymentCondition.address), 0)
assert.strictEqual(await getBalance(token, escrowCondition.address), 0)
assert.strictEqual(await getBalance(token, receivers[0]), amounts[0])
assert.strictEqual(await getBalance(token, receivers[1]), amounts[1])
})
})

})
4 changes: 1 addition & 3 deletions test/unit/templates/AccessTemplate.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,9 @@ contract('AccessTemplate', (accounts) => {
await accessTemplate.createAgreement(agreementId, ...Object.values(agreement))
const realAgreementId = await agreementStoreManager.agreementId(agreementId, accounts[0])

/*
const storedAgreementData = await accessTemplate.getAgreementData(agreementId)
const storedAgreementData = await accessTemplate.getAgreementData(realAgreementId)
assert.strictEqual(storedAgreementData.accessConsumer, agreement.accessConsumer)
assert.strictEqual(storedAgreementData.accessProvider, accounts[0])
*/

const condIds = await testUtils.getAgreementConditionIds(accessTemplate, realAgreementId)
expect(condIds).to.deep.equal(agreement.conditionIds)
Expand Down
4 changes: 1 addition & 3 deletions test/unit/templates/DIDSalesTemplate.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,9 @@ contract('DIDSalesTemplate', (accounts) => {
await didSalesTemplate.createAgreement(agreementId, ...Object.values(agreement))
const realAgreementId = await agreementStoreManager.agreementId(agreementId, accounts[0])

/*
const storedAgreementData = await didSalesTemplate.getAgreementData(agreementId)
const storedAgreementData = await didSalesTemplate.getAgreementData(realAgreementId)
assert.strictEqual(storedAgreementData.accessConsumer, agreement.accessConsumer)
assert.strictEqual(storedAgreementData.accessProvider, accounts[0])
*/

const condIds = await testUtils.getAgreementConditionIds(didSalesTemplate, realAgreementId)
expect(condIds).to.deep.equal(agreement.conditionIds)
Expand Down
8 changes: 0 additions & 8 deletions test/unit/templates/DynamicAccessTemplate.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,6 @@ contract('DynamicAccessTemplate', (accounts) => {
const eventArgs = testUtils.getEventArgsFromTx(result, 'AgreementCreated')
expect(eventArgs._agreementId).to.equal(realAgreementId)
expect(eventArgs._did).to.equal(agreement.did)
// expect(eventArgs._accessProvider).to.equal(accounts[0])
// expect(eventArgs._accessConsumer).to.equal(agreement.accessConsumer)

/*
const storedAgreementData = await dynamicAccessTemplate.getAgreementData(agreementId)
assert.strictEqual(storedAgreementData.accessConsumer, agreement.accessConsumer)
assert.strictEqual(storedAgreementData.accessProvider, accounts[0])
*/

const condIds = await testUtils.getAgreementConditionIds(dynamicAccessTemplate, agreementId)
expect(condIds).to.deep.equal(agreement.conditionIds)
Expand Down
15 changes: 2 additions & 13 deletions test/unit/templates/EscrowComputeExecutionTemplate.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,10 @@ contract('EscrowComputeExecutionTemplate', (accounts) => {

await escrowComputeExecutionTemplate.createAgreement(agreementId, ...Object.values(agreement))
const realAgreementId = await agreementStoreManager.agreementId(agreementId, accounts[0])
/*
const storedAgreementData = await escrowComputeExecutionTemplate.getAgreementData(agreementId)
const storedAgreementData = await escrowComputeExecutionTemplate.getAgreementData(realAgreementId)
assert.strictEqual(storedAgreementData.accessConsumer, agreement.accessConsumer)
assert.strictEqual(storedAgreementData.accessProvider, accounts[0])
*/

const condIds = await testUtils.getAgreementConditionIds(escrowComputeExecutionTemplate, realAgreementId)
expect(condIds).to.deep.equal(agreement.conditionIds)

Expand Down Expand Up @@ -168,16 +167,6 @@ contract('EscrowComputeExecutionTemplate', (accounts) => {
const eventArgs = testUtils.getEventArgsFromTx(result, 'AgreementCreated')
expect(eventArgs._agreementId).to.equal(realAgreementId)
expect(eventArgs._did).to.equal(agreement.did)
/*
expect(eventArgs._accessProvider).to.equal(accounts[0])
expect(eventArgs._accessConsumer).to.equal(agreement.accessConsumer)
const storedAgreement = await agreementStoreManager.getAgreement(agreementId)
expect(storedAgreement.conditionIds)
.to.deep.equal(agreement.conditionIds)
expect(storedAgreement.lastUpdatedBy)
.to.equal(templateId)
*/
})

it.skip('create agreement should set asset provider as accessProvider instead of owner', async () => {
Expand Down
4 changes: 1 addition & 3 deletions test/unit/templates/NFTAccessTemplate.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,9 @@ contract('NFTAccessTemplate', (accounts) => {
await nftAccessTemplate.createAgreement(agreementId, ...Object.values(agreement))
const realAgreementId = await agreementStoreManager.agreementId(agreementId, accounts[0])

/*
const storedAgreementData = await nftAccessTemplate.getAgreementData(agreementId)
const storedAgreementData = await nftAccessTemplate.getAgreementData(realAgreementId)
assert.strictEqual(storedAgreementData.accessConsumer, agreement.accessConsumer)
assert.strictEqual(storedAgreementData.accessProvider, accounts[0])
*/

const condIds = await testUtils.getAgreementConditionIds(nftAccessTemplate, realAgreementId)
expect(condIds).to.deep.equal(agreement.conditionIds)
Expand Down
4 changes: 0 additions & 4 deletions test/unit/templates/NFTSalesTemplate.Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,12 @@ contract('NFTSalesTemplate', (accounts) => {

const realAgreementId = await agreementStoreManager.agreementId(agreementId, accounts[0])

/*
const storedAgreementData = await nftSalesTemplate.getAgreementData(realAgreementId)
assert.strictEqual(storedAgreementData.accessConsumer, agreement.accessConsumer)
assert.strictEqual(storedAgreementData.accessProvider, accounts[0])
*/

// const storedAgreement = await agreementStoreManager.getAgreement(agreementId)
const condIds = await testUtils.getAgreementConditionIds(nftSalesTemplate, realAgreementId)
expect(condIds).to.deep.equal(agreement.conditionIds)
// expect(storedAgreement.lastUpdatedBy).to.equal(templateId)

let i = 0
const conditionTypes = await nftSalesTemplate.getConditionTypes()
Expand Down

0 comments on commit 403d2a6

Please sign in to comment.