Skip to content

Commit

Permalink
We indent only if the chain doesn't belong to a variable declaration …
Browse files Browse the repository at this point in the history
…or a binary operation (#516)
  • Loading branch information
Janther committed May 30, 2021
1 parent b620a89 commit b9de415
Show file tree
Hide file tree
Showing 4 changed files with 261 additions and 3 deletions.
19 changes: 18 additions & 1 deletion src/nodes/MemberAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,28 @@ const isBeginnigOfChain = (path) => {
return true;
};

const shallIndent = (path) => {
let i = 0;
let elderNode = path.getParentNode(i);
while (elderNode) {
if (
elderNode.type === 'VariableDeclarationStatement' ||
elderNode.type === 'BinaryOperation'
)
return false;
i += 1;
elderNode = path.getParentNode(i);
}
return true;
};

const MemberAccess = {
print: ({ node, path, print }) => {
const doc = [
path.call(print, 'expression'),
indent([softline, '.', node.memberName])
shallIndent(path)
? indent([softline, '.', node.memberName])
: [softline, '.', node.memberName]
];

return isBeginnigOfChain(path) ? group(doc) : doc;
Expand Down
21 changes: 21 additions & 0 deletions tests/FunctionCalls/FunctionCalls.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,25 @@ contract FunctionCalls {
voted: true,
});
}
function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) {
address signer =
_hashTypedDataV1(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
)
._hashTypedDataV2(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
)._hashTypedDataV3(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
) .recover(signature);
signer =
_hashTypedDataV1(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
)
._hashTypedDataV2(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
)._hashTypedDataV3(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
) .recover(signature);
return _nonces[req.from] == req.nonce && signer == req.from;
}
}
220 changes: 220 additions & 0 deletions tests/FunctionCalls/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ contract FunctionCalls {
voted: true,
});
}
function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) {
address signer =
_hashTypedDataV1(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
)
._hashTypedDataV2(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
)._hashTypedDataV3(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
) .recover(signature);
signer =
_hashTypedDataV1(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
)
._hashTypedDataV2(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
)._hashTypedDataV3(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
) .recover(signature);
return _nonces[req.from] == req.nonce && signer == req.from;
}
}
=====================================output=====================================
Expand All @@ -41,6 +62,95 @@ contract FunctionCalls {
Voter airbnb = Voter({ weight: 2, voted: true });
}
function verify(ForwardRequest calldata req, bytes calldata signature)
public
view
returns (bool)
{
address signer =
_hashTypedDataV1(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)
._hashTypedDataV2(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)
._hashTypedDataV3(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)
.recover(signature);
signer = _hashTypedDataV1(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)
._hashTypedDataV2(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)
._hashTypedDataV3(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)
.recover(signature);
return _nonces[req.from] == req.nonce && signer == req.from;
}
}
================================================================================
Expand Down Expand Up @@ -70,6 +180,27 @@ contract FunctionCalls {
voted: true,
});
}
function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) {
address signer =
_hashTypedDataV1(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
)
._hashTypedDataV2(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
)._hashTypedDataV3(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
) .recover(signature);
signer =
_hashTypedDataV1(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
)
._hashTypedDataV2(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
)._hashTypedDataV3(
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
) .recover(signature);
return _nonces[req.from] == req.nonce && signer == req.from;
}
}
=====================================output=====================================
Expand All @@ -86,6 +217,95 @@ contract FunctionCalls {
Voter airbnb = Voter({weight: 2, voted: true});
}
function verify(ForwardRequest calldata req, bytes calldata signature)
public
view
returns (bool)
{
address signer =
_hashTypedDataV1(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)
._hashTypedDataV2(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)
._hashTypedDataV3(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)
.recover(signature);
signer = _hashTypedDataV1(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)
._hashTypedDataV2(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)
._hashTypedDataV3(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)
.recover(signature);
return _nonces[req.from] == req.nonce && signer == req.from;
}
}
================================================================================
Expand Down
4 changes: 2 additions & 2 deletions tests/Issues/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ contract Example {
balanceStates[msg.sender][token].balance = balanceStates[msg.sender][
token
]
.balance
.sub(amount);
.balance
.sub(amount);
}
}
Expand Down

0 comments on commit b9de415

Please sign in to comment.