Using truffle , I am able to deploy private smart contracts using privateFor clause. However, I am not able to use in truffle test. I get the following error. Is there a way we can use privateFor ?
Transaction: 0x0e390b0d04d6285bd098f76ebfa961b8be875ce2a744511e13eb312414f835a8 exited with an error (status 0).
Please check that the transaction:
- satisfies all conditions set by Solidity require
statements.
- does not trigger a Solidity revert
statement.
Sample Test
const truffleAssert = require('truffle-assertions');
const DEF_Test = artifacts.require("DEF_Test");
const Testing_V1 = artifacts.require("Testing_V1");
const Event_V1 = artifacts.require("Event_V1");
// Test cases
contract("Testing_V1 Testing", async accounts => {
let Testing_V1Instance;
let Event_V1Instance;
it("1. Setting up Contract instances", async () => {
Testing_V1Instance = await Testing_V1.new();
Event_V1Instance = await Event_V1.new();
})
it("set", async () => {
let result = await Testing_V1Instance.set("ID","Name",["ph1","ph2"],Event_V1Instance.address,
{from:"0x12eac5277d794e1a0d65c95f9fe2b721a86d096f",
privateFor:["l/VcNHe+p+KX79dbGpAydcMiKGkaBbwSkdInlP6PHD0=",
"K76aVoHUc5RkNpkreFd64DYyzxG1UO5aCd05h1u97EA="]});
console.log(result)
});
it("get", async () => {
let result = await Testing_V1Instance.get("ID");
console.log(result)
})
})
Sample code
pragma solidity 0.5.13;
pragma experimental ABIEncoderV2;
import "../definitions/DEF_Test.sol";
import "./Event_V1.sol";
import "../interface/ITesting_V1.sol";
contract Testing_V1 is ITesting_V1 {
mapping (string => DEF_Test.Employee) private mapEmp;
function set(string memory empID, string memory empName,string[] memory phone,address eventAddr) public{
mapEmp[empID].empID = empID;
mapEmp[empID].empName = empName;
mapEmp[empID].phone = phone;
Event_V1(eventAddr).emitEmpEvent(mapEmp[empID]);
}
function get(string memory empID) public view returns (DEF_Test.Employee memory) {
return mapEmp[empID];
}
}
pragma solidity 0.5.13;
pragma experimental ABIEncoderV2;
import "../definitions/DEF_Test.sol";
contract Event_V1 {
event EMP_EVENT(string empID,string empName,string[] phone);
function emitEmpEvent(DEF_Test.Employee memory emp) public {
emit EMP_EVENT(emp.empID,emp.empName,emp.phone);
}
}
pragma solidity 0.5.13;
pragma experimental ABIEncoderV2;
library DEF_Test {
struct Employee {
string empID;
string empName;
string[] phone;
}
}
pragma solidity 0.5.13;
pragma experimental ABIEncoderV2;
import "../definitions/DEF_Test.sol";
interface ITesting_V1 {
function set(string calldata empID, string calldata empName,string[] calldata phone,address eventAddr) external;
function get(string calldata empID) external view returns (DEF_Test.Employee memory);
}