Skip to content

Commit

Permalink
refactor: Remove logs, refactor to conform with mixedCase.
Browse files Browse the repository at this point in the history
Signed-off-by: Sophia Koehler <sophia@perun.network>
  • Loading branch information
sophia1ch committed Sep 17, 2024
1 parent afba2e1 commit aedfbd6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
18 changes: 9 additions & 9 deletions contracts/Adjudicator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ contract Adjudicator {
locked[s],
_channel.state
);
require(Channel.AreBytes32ArraysEqual(subAlloc.ID, _state.channelID), "invalid sub-channel id");
require(Channel.areBytes32ArraysEqual(subAlloc.ID, _state.channelID), "invalid sub-channel id");

uint256[] memory _outcome;
(_outcome, nextIndex) = registerRecursive(
Expand Down Expand Up @@ -163,7 +163,7 @@ contract Adjudicator {
}

// If registered, require newer version and refutation timeout not passed.
(Dispute memory dispute, bool registered) = getDispute(state.channelID[Channel.FindBackendIndex(
(Dispute memory dispute, bool registered) = getDispute(state.channelID[Channel.findBackendIndex(
state.channelID,
state.outcome.backends
)]);
Expand Down Expand Up @@ -210,7 +210,7 @@ contract Adjudicator {
uint256 actorIdx,
bytes memory sig
) external {
Dispute memory dispute = requireGetDispute(state.channelID[Channel.FindBackendIndex(
Dispute memory dispute = requireGetDispute(state.channelID[Channel.findBackendIndex(
state.channelID,
state.outcome.backends
)]);
Expand Down Expand Up @@ -296,7 +296,7 @@ contract Adjudicator {
Channel.validateSignatures(params, state, sigs);

// If registered, require not concluded.
(Dispute memory dispute, bool registered) = getDispute(state.channelID[Channel.FindBackendIndex(
(Dispute memory dispute, bool registered) = getDispute(state.channelID[Channel.findBackendIndex(
state.channelID,
state.outcome.backends
)]);
Expand Down Expand Up @@ -347,7 +347,7 @@ contract Adjudicator {
Channel.Params memory params,
Channel.State memory state
) internal pure {
uint256 zeroIndex = Channel.FindBackendIndex(
uint256 zeroIndex = Channel.findBackendIndex(
state.channelID,
state.outcome.backends
);
Expand All @@ -366,7 +366,7 @@ contract Adjudicator {
Channel.State memory state,
DisputePhase disputePhase
) internal {
uint256 zeroIndex = Channel.FindBackendIndex(
uint256 zeroIndex = Channel.findBackendIndex(
state.channelID,
state.outcome.backends
);
Expand Down Expand Up @@ -472,7 +472,7 @@ contract Adjudicator {
* Reverts if the channel is already concluded.
*/
function concludeSingle(Channel.State memory state) internal {
uint64 zeroIndex = Channel.FindBackendIndex(
uint64 zeroIndex = Channel.findBackendIndex(
state.channelID,
state.outcome.backends
);
Expand Down Expand Up @@ -527,7 +527,7 @@ contract Adjudicator {
for (uint256 i = 0; i < locked.length; i++) {
Channel.SubAlloc memory subAlloc = locked[i];
Channel.State memory subState = subStates[nextIndex++];
require(Channel.AreBytes32ArraysEqual(subAlloc.ID, subState.channelID), "invalid subchannel id");
require(Channel.areBytes32ArraysEqual(subAlloc.ID, subState.channelID), "invalid subchannel id");

uint256[][] memory subOutcome;
(subOutcome, nextIndex) = forceConcludeRecursive(
Expand All @@ -553,7 +553,7 @@ contract Adjudicator {
* Reverts if the channel is not registered.
*/
function forceConcludeSingle(Channel.State memory state) internal {
uint64 zeroIndex = Channel.FindBackendIndex(
uint64 zeroIndex = Channel.findBackendIndex(
state.channelID,
state.outcome.backends
);
Expand Down
10 changes: 5 additions & 5 deletions contracts/Channel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ library Channel {
SubAlloc memory a,
SubAlloc memory b
) internal pure {
require(AreBytes32ArraysEqual(a.ID, b.ID), "SubAlloc: unequal ID");
require(areBytes32ArraysEqual(a.ID, b.ID), "SubAlloc: unequal ID");
Array.requireEqualUint256Array(a.balances, b.balances);
Array.requireEqualUint16Array(a.indexMap, b.indexMap);
}

// @dev AreBytes32ArraysEqual checks if two arrays of bytes32 are equal.
function AreBytes32ArraysEqual(bytes32[] memory arr1, bytes32[] memory arr2) internal pure returns (bool) {
// @dev areBytes32ArraysEqual checks if two arrays of bytes32 are equal.
function areBytes32ArraysEqual(bytes32[] memory arr1, bytes32[] memory arr2) internal pure returns (bool) {
if (arr1.length != arr2.length) {
return false;
}
Expand All @@ -146,11 +146,11 @@ library Channel {
}

/**
* @dev FindBackendIndex finds out which of the channelIDs corresponds to the ethereum encoded channelID.
* @dev findBackendIndex finds out which of the channelIDs corresponds to the ethereum encoded channelID.
* Reverts if none of the channelIDs has a zero backend.
* Optimized for the common case of only one zero backend.
*/
function FindBackendIndex(bytes32[] memory channel, uint256[] memory backends) internal pure returns (uint64) {
function findBackendIndex(bytes32[] memory channel, uint256[] memory backends) internal pure returns (uint64) {
require(channel.length == backends.length, "Array lengths mismatch");

if (backends[0] == 1) return 0;
Expand Down
10 changes: 2 additions & 8 deletions test/Adjudicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,35 +257,29 @@ describe("Adjudicator", function () {
const account2 = signers[3];
parts = [new Participant(await account1.getAddress(), zeroAddress, zeroAddress, zeroAddress), new Participant(await account2.getAddress(), zeroAddress, zeroAddress, zeroAddress)];
const AdjudicatorFactory = await ethers.getContractFactory("Adjudicator") as Adjudicator__factory;
console.log("before deployment");
adj = await AdjudicatorFactory.deploy();
console.log("after deployment");

await adj.waitForDeployment();
adjAddress = await adj.getAddress();
console.log("adjAddress", adjAddress);

const AssetHolderETHFactory = await ethers.getContractFactory("AssetHolderETH") as AssetHolderETH__factory;
ah = await AssetHolderETHFactory.deploy(adjAddress);
console.log("before ah deployment");
await ah.waitForDeployment();

ahAddress = await ah.getAddress();
console.log("ahAddress", ahAddress);
adjInterface = new ethers.Interface(Adjudicator__factory.abi) as AdjudicatorInterface;
const TrivialAppFactory = await ethers.getContractFactory("TrivialApp") as TrivialApp__factory;
appInstance = await TrivialAppFactory.deploy();
await appInstance.waitForDeployment();
appAddress = await appInstance.getAddress();
console.log("appAddress", appAddress);

const chainIDBigInt = await ethers.provider.getNetwork().then(n => n.chainId);
const chainID = Number(chainIDBigInt);
asset = new Asset(chainID, await ah.getAddress(), zeroAddress);
backend = [1];

params = new Params(appAddress, timeout, nonce, [parts[A], parts[B]], true);
console.log("before calcID");
channelID = [params.channelID()];
console.log("channelID", channelID);

});

Expand Down

0 comments on commit aedfbd6

Please sign in to comment.