From 3a02d0df0b3d1ebb34d285d981a32d76212fa060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Cuesta=20Ca=C3=B1ada?= Date: Thu, 16 Jan 2020 15:39:50 +0000 Subject: [PATCH] Tweaked the tests to follow oz structure. --- test/drafts/Enumerables.test.js | 128 ++++++++++++++++---------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/test/drafts/Enumerables.test.js b/test/drafts/Enumerables.test.js index 60d0d239d..c5cbbf38f 100644 --- a/test/drafts/Enumerables.test.js +++ b/test/drafts/Enumerables.test.js @@ -12,7 +12,7 @@ const tailData = '0x0000000000000000000000000000000000000003'; describe('Enumerable', function () { beforeEach(async function () { - this.enumerables = await Enumerables.new(); + this.enumerables = await EnumerablesMock.new(); }); // it('starts at zero', async function () { @@ -20,15 +20,15 @@ describe('Enumerable', function () { // }); /** - * Test the two contract methods + * Test the two describe methods * @test {Enumerable#set} and {Enumerable#get} */ it('Constructor variables.', async function () { - // expect(await enumerables.enumerable().idCounter()).toNumber()).to.be.equal(1); + // expect(await this.enumerables.enumerable().idCounter()).toNumber()).to.be.equal(1); }); it('get on a non existing object returns (0,0,0,0).', async function () { - const result = (await enumerables.testGet(0)); + const result = (await this.enumerables.testGet(0)); expect(result[0].toNumber()).to.be.equal(0); expect(result[1].toNumber()).to.be.equal(0); expect(result[2].toNumber()).to.be.equal(0); @@ -37,7 +37,7 @@ describe('Enumerable', function () { it('appends an object at the head - event emission.', async function () { const objectEvent = ( - await enumerables.testAppend(headData) + await this.enumerables.testAppend(headData) ).logs[0]; expect(objectEvent.args.id.toNumber()).to.be.equal(1); expect(objectEvent.args.data).to.be.equal(headData); @@ -45,10 +45,10 @@ describe('Enumerable', function () { it('appends an object at the head - data storage.', async function () { const objectId = ( - await enumerables.testAppend(headData) + await this.enumerables.testAppend(headData) ).logs[0].args.id.toNumber(); - const result = (await enumerables.testGet(objectId)); + const result = (await this.enumerables.testGet(objectId)); expect(result[0].toNumber()).to.be.equal(objectId); expect(result[1].toNumber()).to.be.equal(0); expect(result[2].toNumber()).to.be.equal(0); @@ -57,83 +57,83 @@ describe('Enumerable', function () { it('appends two objects.', async function () { const objectOneId = ( - await enumerables.testAppend(middleData) + await this.enumerables.testAppend(middleData) ).logs[0].args.id.toNumber(); const objectTwoId = ( - await enumerables.testAppend(headData) + await this.enumerables.testAppend(headData) ).logs[0].args.id.toNumber(); - const objectOne = (await enumerables.testGet(objectOneId)); + const objectOne = (await this.enumerables.testGet(objectOneId)); expect(objectOne[0].toNumber()).to.be.equal(objectOneId); expect(objectOne[1].toNumber()).to.be.equal(0); expect(objectOne[2].toNumber()).to.be.equal(objectTwoId); expect(objectOne[3]).to.be.equal(middleData); - const objectTwo = (await enumerables.testGet(objectTwoId)); + const objectTwo = (await this.enumerables.testGet(objectTwoId)); expect(objectTwo[0].toNumber()).to.be.equal(objectTwoId); expect(objectTwo[1].toNumber()).to.be.equal(objectOneId); expect(objectTwo[2].toNumber()).to.be.equal(0); expect(objectTwo[3]).to.be.equal(headData); - // expect(((await enumerables.head()).toNumber())).to.be.equal(objectTwoId); + // expect(((await this.enumerables.head()).toNumber())).to.be.equal(objectTwoId); }); }); -contract('Enumerable - length', (accounts) => { +describe('Enumerable - length', (accounts) => { beforeEach(async function () { - this.enumerables = await Enumerables.new(); + this.this.enumerables = await EnumerablesMock.new(); }); - it('Retrieves the length of an empty enumerables.', async function () { - const resultId = (await enumerables.testLength()); + it('Retrieves the length of an empty this.enumerables.', async function () { + const resultId = (await this.enumerables.testLength()); expect(resultId.toNumber()).to.be.equal(0); }); - it('Retrieves the length of an enumerables.', async function () { + it('Retrieves the length of an this.enumerables.', async function () { tailId = ( - await enumerables.testAppend(tailData) + await this.enumerables.testAppend(tailData) ).logs[0].args.id.toNumber(); middleId = ( - await enumerables.testAppend(middleData) + await this.enumerables.testAppend(middleData) ).logs[0].args.id.toNumber(); headId = ( - await enumerables.testAppend(headData) + await this.enumerables.testAppend(headData) ).logs[0].args.id.toNumber(); - const resultId = (await enumerables.testLength()); + const resultId = (await this.enumerables.testLength()); expect(resultId.toNumber()).to.be.equal(3); }); }); -/** @test {Enumerable} contract */ -contract('Enumerable - contains', (accounts) => { +/** @test {Enumerable} describe */ +describe('Enumerable - contains', (accounts) => { beforeEach(async function () { - this.enumerables = await Enumerables.new(); + this.this.enumerables = await EnumerablesMock.new(); tailId = ( - await enumerables.testAppend(tailData) + await this.enumerables.testAppend(tailData) ).logs[0].args.id.toNumber(); middleId = ( - await enumerables.testAppend(middleData) + await this.enumerables.testAppend(middleData) ).logs[0].args.id.toNumber(); }); it('Returns false for empty data.', async function () { - const resultId = (await enumerables.testContains(emptyData)); + const resultId = (await this.enumerables.testContains(emptyData)); expect(resultId).to.be.false; }); it('Returns true for existing data.', async function () { - const resultId = (await enumerables.testContains(tailData)); + const resultId = (await this.enumerables.testContains(tailData)); expect(resultId).to.be.true; }); it('Returns false for non existing data.', async function () { - const resultId = (await enumerables.testContains(headData)); + const resultId = (await this.enumerables.testContains(headData)); expect(resultId).to.be.false; }); }); -/** @test {Enumerable} contract */ -/* contract('Enumerable - enumerate', (accounts) => { +/** @test {Enumerable} describe */ +/* describe('Enumerable - enumerate', (accounts) => { let enumerable: EnumerablesMockInstance; let headId: number; @@ -141,56 +141,56 @@ contract('Enumerable - contains', (accounts) => { let tailId: number; beforeEach(async function () { - enumerable = await Enumerables.new(); + enumerable = await EnumerablesMock.new(); tailId = ( - await enumerables.testAppend(tailData) + await this.enumerables.testAppend(tailData) ).logs[0].args.id.toNumber(); middleId = ( - await enumerables.testAppend(middleData) + await this.enumerables.testAppend(middleData) ).logs[0].args.id.toNumber(); headId = ( - await enumerables.testAppend(headData) + await this.enumerables.testAppend(headData) ).logs[0].args.id.toNumber(); }); it('finds an id for given data.', async function () { - let resultId = (await enumerables.findIdForData(headData)); + let resultId = (await this.enumerables.findIdForData(headData)); expect(resultId.toNumber()).to.be.equal(headId); - resultId = (await enumerables.findIdForData(middleData)); + resultId = (await this.enumerables.findIdForData(middleData)); expect(resultId.toNumber()).to.be.equal(middleId); - resultId = (await enumerables.findIdForData(tailData)); + resultId = (await this.enumerables.findIdForData(tailData)); expect(resultId.toNumber()).to.be.equal(tailId); }); }); */ -/** @test {Enumerable} contract */ -contract('Enumerable - remove', (accounts) => { +/** @test {Enumerable} describe */ +describe('Enumerable - remove', (accounts) => { beforeEach(async function () { - this.enumerables = await Enumerables.new(); + this.this.enumerables = await EnumerablesMock.new(); tailId = ( - await enumerables.testAppend(tailData) + await this.enumerables.testAppend(tailData) ).logs[0].args.id.toNumber(); middleId = ( - await enumerables.testAppend(middleData) + await this.enumerables.testAppend(middleData) ).logs[0].args.id.toNumber(); headId = ( - await enumerables.testAppend(headData) + await this.enumerables.testAppend(headData) ).logs[0].args.id.toNumber(); }); it('removes the head.', async function () { const removedId = ( - await enumerables.testRemove(headId) + await this.enumerables.testRemove(headId) ).logs[1].args.id.toNumber(); - // expect(((await enumerables.head()).toNumber())).to.be.equal(middleId); + // expect(((await this.enumerables.head()).toNumber())).to.be.equal(middleId); - const middleObject = (await enumerables.testGet(middleId)); + const middleObject = (await this.enumerables.testGet(middleId)); expect(middleObject[0].toNumber()).to.be.equal(middleId); expect(middleObject[1].toNumber()).to.be.equal(tailId); expect(middleObject[2].toNumber()).to.be.equal(0); expect(middleObject[3]).to.be.equal(middleData); - const tailObject = (await enumerables.testGet(tailId)); + const tailObject = (await this.enumerables.testGet(tailId)); expect(tailObject[0].toNumber()).to.be.equal(tailId); expect(tailObject[1].toNumber()).to.be.equal(0); expect(tailObject[2].toNumber()).to.be.equal(middleId); @@ -199,17 +199,17 @@ contract('Enumerable - remove', (accounts) => { it('removes the tail.', async function () { const removedId = ( - await enumerables.testRemove(tailId) + await this.enumerables.testRemove(tailId) ).logs[1].args.id.toNumber(); - // expect(((await enumerables.head()).toNumber())).to.be.equal(headId); + // expect(((await this.enumerables.head()).toNumber())).to.be.equal(headId); - const headObject = (await enumerables.testGet(headId)); + const headObject = (await this.enumerables.testGet(headId)); expect(headObject[0].toNumber()).to.be.equal(headId); expect(headObject[1].toNumber()).to.be.equal(middleId); expect(headObject[2].toNumber()).to.be.equal(0); expect(headObject[3]).to.be.equal(headData); - const middleObject = (await enumerables.testGet(middleId)); + const middleObject = (await this.enumerables.testGet(middleId)); expect(middleObject[0].toNumber()).to.be.equal(middleId); expect(middleObject[1].toNumber()).to.be.equal(0); expect(middleObject[2].toNumber()).to.be.equal(headId); @@ -218,17 +218,17 @@ contract('Enumerable - remove', (accounts) => { it('removes the middle.', async function () { const removedId = ( - await enumerables.testRemove(middleId) + await this.enumerables.testRemove(middleId) ).logs[1].args.id.toNumber(); - // expect(((await enumerables.head()).toNumber())).to.be.equal(headId); + // expect(((await this.enumerables.head()).toNumber())).to.be.equal(headId); - const headObject = (await enumerables.testGet(headId)); + const headObject = (await this.enumerables.testGet(headId)); expect(headObject[0].toNumber()).to.be.equal(headId); expect(headObject[1].toNumber()).to.be.equal(tailId); expect(headObject[2].toNumber()).to.be.equal(0); expect(headObject[3]).to.be.equal(headData); - const tailObject = (await enumerables.testGet(tailId)); + const tailObject = (await this.enumerables.testGet(tailId)); expect(tailObject[0].toNumber()).to.be.equal(tailId); expect(tailObject[1].toNumber()).to.be.equal(0); expect(tailObject[2].toNumber()).to.be.equal(headId); @@ -236,15 +236,15 @@ contract('Enumerable - remove', (accounts) => { }); it('removes all.', async function () { - (await enumerables.testRemove(headId)).logs[1].args.id.toNumber(); - // expect(((await enumerables.head()).toNumber())).to.be.equal(middleId); + (await this.enumerables.testRemove(headId)).logs[1].args.id.toNumber(); + // expect(((await this.enumerables.head()).toNumber())).to.be.equal(middleId); - (await enumerables.testRemove(tailId)).logs[1].args.id.toNumber(); - // expect(((await enumerables.head()).toNumber())).to.be.equal(middleId); - // expect(((await enumerables.tail()).toNumber())).to.be.equal(middleId); + (await this.enumerables.testRemove(tailId)).logs[1].args.id.toNumber(); + // expect(((await this.enumerables.head()).toNumber())).to.be.equal(middleId); + // expect(((await this.enumerables.tail()).toNumber())).to.be.equal(middleId); - (await enumerables.testRemove(middleId)).logs[1].args.id.toNumber(); - // expect(((await enumerables.head()).toNumber())).to.be.equal(0); - // expect(((await enumerables.tail()).toNumber())).to.be.equal(0); + (await this.enumerables.testRemove(middleId)).logs[1].args.id.toNumber(); + // expect(((await this.enumerables.head()).toNumber())).to.be.equal(0); + // expect(((await this.enumerables.tail()).toNumber())).to.be.equal(0); }); });