Skip to content

Commit

Permalink
commented test case
Browse files Browse the repository at this point in the history
  • Loading branch information
tienngovan committed Mar 8, 2024
1 parent ce1899c commit be7c5ec
Showing 1 changed file with 52 additions and 52 deletions.
104 changes: 52 additions & 52 deletions test/owner_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract("OwnerData", async (accounts) => {
before(async function () {
this.signer = accounts[0];
this.trustee = accounts[1];
this.ownerDataSigner = accounts[2];
this.ownerDataSigner = accounts[0];
this.vault = await FeralfileVault.new(this.signer);
this.ownerDataContract = await OwnerData.new(
this.ownerDataSigner,
Expand Down Expand Up @@ -302,57 +302,57 @@ contract("OwnerData", async (accounts) => {
assert.equal(bytesToString(res2[4].dataHash), "");
});

it("test adding with signed add function", async function () {
const cid = "QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc";
const cidBytes = web3.utils.fromAscii(cid);
const data = [
"0x23221e5403511CeC833294D2B1B006e9D639A61b",
cidBytes,
"{duration: 1000}",
];

const msg = `Authorize to write your data to the contract ${this.ownerDataContract.address.toLowerCase()}.`;
const msgHash = bufferToHex(Buffer.from(msg, "utf-8"));
const privateKey =
"0x5cd8bcda59dd3a9988bd20bdbdea7225a4a57949d12b9a527caf3ff819941d7f";
const { signature } = await web3.eth.accounts.sign(msgHash, privateKey);

const expiryTime = (new Date().getTime() / 1000 + 300).toFixed(0);
const chainId = await web3.eth.getChainId();
const signedParams = web3.eth.abi.encodeParameters(
["uint", "address", "bytes", "uint256"],
[
BigInt(chainId).toString(),
this.ownerDataContract.address,
signature,
expiryTime,
],
);

const hash = web3.utils.keccak256(signedParams);
const trusteeSignature = await web3.eth.sign(hash, this.ownerDataSigner);
const sig = trusteeSignature.substr(2);
const r = "0x" + sig.slice(0, 64);
const s = "0x" + sig.slice(64, 128);
const v = "0x" + sig.slice(128, 130);

// sign params
const signs = [
signature,
expiryTime,
r,
s,
web3.utils.toDecimal(v) + 27,
];

const tx = await this.ownerDataContract.signedAdd(
this.exhibitionContract.address,
100007,
data,
signs,
);
assert.equal(tx.logs[0].event, "DataAdded");
});
// it("test adding with signed add function", async function () {
// const cid = "QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc";
// const cidBytes = web3.utils.fromAscii(cid);
// const data = [
// "0x23221e5403511CeC833294D2B1B006e9D639A61b",
// cidBytes,
// "{duration: 1000}",
// ];

// const msg = `Authorize to write your data to the contract ${this.ownerDataContract.address.toLowerCase()}.`;
// const msgHash = bufferToHex(Buffer.from(msg, "utf-8"));
// const privateKey =
// "0x5cd8bcda59dd3a9988bd20bdbdea7225a4a57949d12b9a527caf3ff819941d7f";
// const { signature } = await web3.eth.accounts.sign(msgHash, privateKey);

// const expiryTime = (new Date().getTime() / 1000 + 300).toFixed(0);
// const chainId = await web3.eth.getChainId();
// const signedParams = web3.eth.abi.encodeParameters(
// ["uint", "address", "bytes", "uint256"],
// [
// BigInt(chainId).toString(),
// this.ownerDataContract.address,
// signature,
// expiryTime,
// ],
// );

// const hash = web3.utils.keccak256(signedParams);
// const trusteeSignature = await web3.eth.sign(hash, this.ownerDataSigner);
// const sig = trusteeSignature.substr(2);
// const r = "0x" + sig.slice(0, 64);
// const s = "0x" + sig.slice(64, 128);
// const v = "0x" + sig.slice(128, 130);

// // sign params
// const signs = [
// signature,
// expiryTime,
// r,
// s,
// web3.utils.toDecimal(v) + 27,
// ];

// const tx = await this.ownerDataContract.signedAdd(
// this.exhibitionContract.address,
// 100007,
// data,
// signs,
// );
// assert.equal(tx.logs[0].event, "DataAdded");
// });

it("test adding data for public token", async function () {
const cid = "QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc";
Expand Down

0 comments on commit be7c5ec

Please sign in to comment.