Skip to content

Commit c020217

Browse files
committed
Thank you @MichalZalecki for pointing out the removing document error. more detailed in #17
1 parent d9fbea9 commit c020217

5 files changed

Lines changed: 127 additions & 118 deletions

File tree

contracts/ERC1410/ERC1410Basic.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ contract ERC1410Basic {
8585
// some tokens of the same partition as well (To avoid the array index out of bound error).
8686
// Note- There is no operator used for the execution of this call so `_operator` value in
8787
// in event is address(0) same for the `_operatorData`
88-
_transferByPartition(msg.sender, _to, _value, _partition, _data, address(0), "0x0");
88+
_transferByPartition(msg.sender, _to, _value, _partition, _data, address(0), "");
8989
}
9090

9191
/// @notice The standard provides an on-chain function to determine whether a transfer will succeed,

contracts/ERC1410/ERC1410Standard.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ contract ERC1410Standard is IERC1410, ERC1410Operator, Ownable {
3333
/// @param _data Additional data attached to the burning of tokens
3434
function redeemByPartition(bytes32 _partition, uint256 _value, bytes _data) external {
3535
// Add the function to validate the `_data` parameter
36-
_redeemByPartition(_partition, msg.sender, address(0), _value, _data, "0x0");
36+
_redeemByPartition(_partition, msg.sender, address(0), _value, _data, "");
3737
}
3838

3939
/// @notice Decreases totalSupply and the corresponding amount of the specified partition of tokenHolder

contracts/ERC1643/ERC1643.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ contract ERC1643 is IERC1643, Ownable {
5454
uint256 index = _docIndexes[_name] - 1;
5555
if (index != _docNames.length - 1) {
5656
_docNames[index] = _docNames[_docNames.length - 1];
57-
_docIndexes[_name] = index + 1;
57+
_docIndexes[_docNames[index]] = index + 1;
5858
}
5959
_docNames.length--;
6060
emit DocumentRemoved(_name, _documents[_name].uri, _documents[_name].docHash);

test/erc1410.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ const zero_address = "0x0000000000000000000000000000000000000000";
126126
assert.equal(tx.logs[0].args._to, tokenHolder1);
127127
assert.equal(web3.utils.fromWei((tx.logs[0].args._value).toString()), 5);
128128
assert.equal(web3.utils.toUtf8(tx.logs[0].args._data), "");
129-
assert.equal(web3.utils.toUtf8(tx.logs[0].args._operatorData), "0x0");
129+
assert.equal(web3.utils.toUtf8(tx.logs[0].args._operatorData), "");
130130
});
131-
132131
})
133132
});
134133
});

test/erc1643.js

Lines changed: 123 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const docHash = "hello";
1919
const empty_hash = "0x0000000000000000000000000000000000000000000000000000000000000000";
2020

2121
async function latestTime() {
22-
return (await web3.eth.getBlock("latest")).timestamp;
22+
return (await web3.eth.getBlock("latest")).timestamp;
2323
}
2424

2525
before(async () => {
@@ -33,113 +33,121 @@ const empty_hash = "0x0000000000000000000000000000000000000000000000000000000000
3333

3434
describe(`Test cases for the ERC1643 contract\n`, async () => {
3535

36-
describe(`Test cases for the setDocument() function of the ERC1643\n`, async() => {
37-
38-
it("\tShould failed in executing the setDocument() function because msg.sender is not authorised\n", async() => {
39-
await catchRevert(
40-
erc1643.setDocument("doc1", "https://www.gogl.bts.fly", "0x0", {from: account1})
41-
);
42-
});
43-
44-
it("\tShould failed to set a document details as name is empty\n", async() => {
45-
await catchRevert(
46-
erc1643.setDocument("", "https://www.gogl.bts.fly", "0x0", {from: tokenOwner})
47-
);
48-
});
49-
50-
it("\tShould failed to set a document details as URI is empty\n", async() => {
51-
await catchRevert(
52-
erc1643.setDocument("doc1", "", "0x0", {from: tokenOwner})
53-
);
54-
});
55-
56-
it("\tShould sucessfully add the document details in the `_documents` mapping and change the length of the `_docsNames`\n", async() => {
57-
let tx = await erc1643.setDocument("doc1", uri, docHash, {from: tokenOwner});
58-
assert.equal(web3.utils.toUtf8(tx.logs[0].args._name), "doc1");
59-
assert.equal(tx.logs[0].args._uri, uri);
60-
assert.equal(web3.utils.toUtf8(tx.logs[0].args._documentHash), docHash);
61-
assert.equal((await erc1643.getAllDocuments.call()).length, 1);
62-
});
63-
64-
it("\tShould successfully add the new document and allow the empty docHash to be added in the `Document` structure\n", async() => {
65-
let tx = await erc1643.setDocument("doc2", uri, "0x0", {from: tokenOwner});
66-
assert.equal(web3.utils.toUtf8(tx.logs[0].args._name), "doc2");
67-
assert.equal(tx.logs[0].args._uri, uri);
68-
assert.equal(tx.logs[0].args._documentHash, empty_hash);
69-
assert.equal((await erc1643.getAllDocuments.call()).length, 2);
70-
});
71-
72-
it("\tShould successfully update the existing document and length of `_docsNames` should remain unaffected\n", async() => {
73-
let tx = await erc1643.setDocument("doc2", "https://www.bts.l", "0x0", {from: tokenOwner});
74-
assert.equal(web3.utils.toUtf8(tx.logs[0].args._name), "doc2");
75-
assert.equal(tx.logs[0].args._uri, "https://www.bts.l");
76-
assert.equal(tx.logs[0].args._documentHash, empty_hash);
77-
assert.equal((await erc1643.getAllDocuments.call()).length, 2);
78-
});
79-
80-
describe("Test cases for the getters functions\n", async()=> {
81-
82-
it("\tShould get the details of existed document\n", async() => {
83-
let doc1Details = await erc1643.getDocument.call("doc1");
84-
assert.equal(doc1Details[0], uri);
85-
assert.equal(web3.utils.toUtf8(doc1Details[1]), docHash);
86-
assert.closeTo(doc1Details[2].toNumber(), await latestTime(), 2);
87-
88-
let doc2Details = await erc1643.getDocument.call("doc2");
89-
assert.equal(doc2Details[0], "https://www.bts.l");
90-
assert.equal(doc2Details[1], empty_hash);
91-
assert.closeTo(doc2Details[2].toNumber(), await latestTime(), 2);
92-
});
93-
94-
it("\tShould get the details of the non-existed document it means every value should be zero\n", async() => {
95-
let doc3Details = await erc1643.getDocument.call("doc3");
96-
assert.equal(doc3Details[0], "");
97-
assert.equal(web3.utils.toUtf8(doc3Details[1]), "");
98-
assert.equal(doc3Details[2], 0);
99-
});
100-
101-
it("\tShould get all the documents present in the contract\n", async() => {
102-
let allDocs = await erc1643.getAllDocuments.call()
103-
assert.equal(allDocs.length, 2);
104-
assert.equal(web3.utils.toUtf8(allDocs[0]), "doc1");
105-
assert.equal(web3.utils.toUtf8(allDocs[1]), "doc2");
106-
});
107-
})
108-
});
109-
110-
describe("Test cases for the removeDocument()\n", async() => {
111-
112-
it("\tShould failed to remove document because msg.sender is not authorised\n", async() => {
113-
await catchRevert(
114-
erc1643.removeDocument("doc2", {from: account1})
115-
);
116-
});
117-
118-
it("\tShould failed to remove the document that is not existed in the contract\n", async() => {
119-
await catchRevert(
120-
erc1643.removeDocument("doc3", {from: tokenOwner})
121-
);
122-
});
123-
124-
it("\tShould succssfully remove the document from the contract which is present in the last index of the `_docsName` and check the params of the `DocumentRemoved` event\n", async() => {
125-
// first add the new document
126-
await erc1643.setDocument("doc3", "https://www.bts.l", "0x0", {from: tokenOwner});
127-
// as this will be last in the array so remove this
128-
let tx = await erc1643.removeDocument("doc3", {from: tokenOwner});
129-
assert.equal(web3.utils.toUtf8(tx.logs[0].args._name), "doc3");
130-
assert.equal(tx.logs[0].args._uri, "https://www.bts.l");
131-
assert.equal(tx.logs[0].args._documentHash, empty_hash);
132-
assert.equal((await erc1643.getAllDocuments.call()).length, 2);
133-
134-
// remove the document that is not last in the `docsName` array
135-
tx = await erc1643.removeDocument("doc1", {from: tokenOwner});
136-
assert.equal(web3.utils.toUtf8(tx.logs[0].args._name), "doc1");
137-
assert.equal(tx.logs[0].args._uri, uri);
138-
assert.equal(web3.utils.toUtf8(tx.logs[0].args._documentHash), docHash);
139-
assert.equal((await erc1643.getAllDocuments.call()).length, 1);
140-
});
141-
142-
describe("Test cases for the getters functions\n", async()=> {
36+
describe(`Test cases for the setDocument() function of the ERC1643\n`, async() => {
37+
38+
it("\tShould failed in executing the setDocument() function because msg.sender is not authorised\n", async() => {
39+
await catchRevert(
40+
erc1643.setDocument("doc1", "https://www.gogl.bts.fly", "0x0", {from: account1})
41+
);
42+
});
43+
44+
it("\tShould failed to set a document details as name is empty\n", async() => {
45+
await catchRevert(
46+
erc1643.setDocument("", "https://www.gogl.bts.fly", "0x0", {from: tokenOwner})
47+
);
48+
});
49+
50+
it("\tShould failed to set a document details as URI is empty\n", async() => {
51+
await catchRevert(
52+
erc1643.setDocument("doc1", "", "0x0", {from: tokenOwner})
53+
);
54+
});
55+
56+
it("\tShould sucessfully add the document details in the `_documents` mapping and change the length of the `_docsNames`\n", async() => {
57+
let tx = await erc1643.setDocument("doc1", uri, docHash, {from: tokenOwner});
58+
assert.equal(web3.utils.toUtf8(tx.logs[0].args._name), "doc1");
59+
assert.equal(tx.logs[0].args._uri, uri);
60+
assert.equal(web3.utils.toUtf8(tx.logs[0].args._documentHash), docHash);
61+
assert.equal((await erc1643.getAllDocuments.call()).length, 1);
62+
});
63+
64+
it("\tShould successfully add the new document and allow the empty docHash to be added in the `Document` structure\n", async() => {
65+
let tx = await erc1643.setDocument("doc2", uri, "0x0", {from: tokenOwner});
66+
assert.equal(web3.utils.toUtf8(tx.logs[0].args._name), "doc2");
67+
assert.equal(tx.logs[0].args._uri, uri);
68+
assert.equal(tx.logs[0].args._documentHash, empty_hash);
69+
assert.equal((await erc1643.getAllDocuments.call()).length, 2);
70+
});
71+
72+
it("\tShould successfully update the existing document and length of `_docsNames` should remain unaffected\n", async() => {
73+
let tx = await erc1643.setDocument("doc2", "https://www.bts.l", "0x0", {from: tokenOwner});
74+
assert.equal(web3.utils.toUtf8(tx.logs[0].args._name), "doc2");
75+
assert.equal(tx.logs[0].args._uri, "https://www.bts.l");
76+
assert.equal(tx.logs[0].args._documentHash, empty_hash);
77+
assert.equal((await erc1643.getAllDocuments.call()).length, 2);
78+
});
79+
80+
describe("Test cases for the getters functions\n", async()=> {
81+
82+
it("\tShould get the details of existed document\n", async() => {
83+
let doc1Details = await erc1643.getDocument.call("doc1");
84+
assert.equal(doc1Details[0], uri);
85+
assert.equal(web3.utils.toUtf8(doc1Details[1]), docHash);
86+
assert.closeTo(doc1Details[2].toNumber(), await latestTime(), 2);
87+
88+
let doc2Details = await erc1643.getDocument.call("doc2");
89+
assert.equal(doc2Details[0], "https://www.bts.l");
90+
assert.equal(doc2Details[1], empty_hash);
91+
assert.closeTo(doc2Details[2].toNumber(), await latestTime(), 2);
92+
});
93+
94+
it("\tShould get the details of the non-existed document it means every value should be zero\n", async() => {
95+
let doc3Details = await erc1643.getDocument.call("doc3");
96+
assert.equal(doc3Details[0], "");
97+
assert.equal(web3.utils.toUtf8(doc3Details[1]), "");
98+
assert.equal(doc3Details[2], 0);
99+
});
100+
101+
it("\tShould get all the documents present in the contract\n", async() => {
102+
let allDocs = await erc1643.getAllDocuments.call()
103+
assert.equal(allDocs.length, 2);
104+
assert.equal(web3.utils.toUtf8(allDocs[0]), "doc1");
105+
assert.equal(web3.utils.toUtf8(allDocs[1]), "doc2");
106+
});
107+
})
108+
});
109+
110+
describe("Test cases for the removeDocument()\n", async() => {
111+
112+
it("\tShould failed to remove document because msg.sender is not authorised\n", async() => {
113+
await catchRevert(
114+
erc1643.removeDocument("doc2", {from: account1})
115+
);
116+
});
117+
118+
it("\tShould failed to remove the document that is not existed in the contract\n", async() => {
119+
await catchRevert(
120+
erc1643.removeDocument("doc3", {from: tokenOwner})
121+
);
122+
});
123+
124+
it("\tShould succssfully remove the document from the contract which is present in the last index of the `_docsName` and check the params of the `DocumentRemoved` event\n", async() => {
125+
// first add the new document
126+
await erc1643.setDocument("doc3", "https://www.bts.l", "0x0", {from: tokenOwner});
127+
// as this will be last in the array so remove this
128+
let tx = await erc1643.removeDocument("doc3", {from: tokenOwner});
129+
assert.equal(web3.utils.toUtf8(tx.logs[0].args._name), "doc3");
130+
assert.equal(tx.logs[0].args._uri, "https://www.bts.l");
131+
assert.equal(tx.logs[0].args._documentHash, empty_hash);
132+
assert.equal((await erc1643.getAllDocuments.call()).length, 2);
133+
134+
// remove the document that is not last in the `docsName` array
135+
tx = await erc1643.removeDocument("doc1", {from: tokenOwner});
136+
assert.equal(web3.utils.toUtf8(tx.logs[0].args._name), "doc1");
137+
assert.equal(tx.logs[0].args._uri, uri);
138+
assert.equal(web3.utils.toUtf8(tx.logs[0].args._documentHash), docHash);
139+
assert.equal((await erc1643.getAllDocuments.call()).length, 1);
140+
});
141+
142+
it("\t Should delete the doc to validate the #17 issue problem", async() => {
143+
let tx = await erc1643.removeDocument("doc2", {from: tokenOwner});
144+
assert.equal(web3.utils.toUtf8(tx.logs[0].args._name), "doc2");
145+
assert.equal(tx.logs[0].args._uri, "https://www.bts.l");
146+
assert.equal(web3.utils.toUtf8(tx.logs[0].args._documentHash), '');
147+
assert.equal((await erc1643.getAllDocuments.call()).length, 0);
148+
});
149+
150+
describe("Test cases for the getters functions\n", async()=> {
143151

144152
it("\tShould get the details of the non-existed (earlier was present but get removed ) document it means every value should be zero\n", async() => {
145153
let doc1Details = await erc1643.getDocument.call("doc1");
@@ -149,11 +157,13 @@ const empty_hash = "0x0000000000000000000000000000000000000000000000000000000000
149157
});
150158

151159
it("\tShould get all the documents present in the contract which should be 1\n", async() => {
160+
// add one doc before the getter call
161+
await erc1643.setDocument("doc4", "https://www.bts.l", docHash, {from: tokenOwner})
152162
let allDocs = await erc1643.getAllDocuments.call()
153163
assert.equal(allDocs.length, 1);
154-
assert.equal(web3.utils.toUtf8(allDocs[0]), "doc2");
164+
assert.equal(web3.utils.toUtf8(allDocs[0]), "doc4");
155165
});
156-
});
157-
})
158-
});
159-
});
166+
});
167+
})
168+
});
169+
});

0 commit comments

Comments
 (0)