Skip to content

Commit

Permalink
test state in upgrade tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RnkSngh committed Mar 18, 2024
1 parent 66d6c30 commit 2343e16
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 338 deletions.
18 changes: 9 additions & 9 deletions contracts/core/Dispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ contract Dispatcher is OwnableUpgradeable, UUPSUpgradeable, IDispatcher {
string public portPrefix;
uint32 public portPrefixLen;

mapping(address => mapping(bytes32 => Channel)) public portChannelMap;
mapping(address => mapping(bytes32 => uint64)) public nextSequenceSend;
mapping(address => mapping(bytes32 => Channel)) portChannelMap;

Check failure on line 42 in contracts/core/Dispatcher.sol

View workflow job for this annotation

GitHub Actions / lint

'portChannelMap' should start with _
mapping(address => mapping(bytes32 => uint64)) nextSequenceSend;

Check failure on line 43 in contracts/core/Dispatcher.sol

View workflow job for this annotation

GitHub Actions / lint

'nextSequenceSend' should start with _
// keep track of received packets' sequences to ensure channel ordering is enforced for ordered channels
mapping(address => mapping(bytes32 => uint64)) public nextSequenceRecv;
mapping(address => mapping(bytes32 => uint64)) public nextSequenceAck;
mapping(address => mapping(bytes32 => uint64)) nextSequenceRecv;

Check failure on line 45 in contracts/core/Dispatcher.sol

View workflow job for this annotation

GitHub Actions / lint

'nextSequenceRecv' should start with _
mapping(address => mapping(bytes32 => uint64)) nextSequenceAck;

Check failure on line 46 in contracts/core/Dispatcher.sol

View workflow job for this annotation

GitHub Actions / lint

'nextSequenceAck' should start with _
// only stores a bit to mark packet has not been ack'ed or timed out yet; actual IBC packet verification is done on
// Polymer chain.
// Keep track of sent packets
mapping(address => mapping(bytes32 => mapping(uint64 => bool))) public sendPacketCommitment;
mapping(address => mapping(bytes32 => mapping(uint64 => bool))) sendPacketCommitment;

Check failure on line 50 in contracts/core/Dispatcher.sol

View workflow job for this annotation

GitHub Actions / lint

'sendPacketCommitment' should start with _
// keep track of received packets to prevent replay attack
mapping(address => mapping(bytes32 => mapping(uint64 => bool))) public recvPacketReceipt;
mapping(address => mapping(bytes32 => mapping(uint64 => bool))) recvPacketReceipt;

Check failure on line 52 in contracts/core/Dispatcher.sol

View workflow job for this annotation

GitHub Actions / lint

'recvPacketReceipt' should start with _
// keep track of outbound ack packets to prevent replay attack
mapping(address => mapping(bytes32 => mapping(uint64 => bool))) public ackPacketCommitment;
mapping(address => mapping(bytes32 => mapping(uint64 => bool))) ackPacketCommitment;

Check failure on line 54 in contracts/core/Dispatcher.sol

View workflow job for this annotation

GitHub Actions / lint

'ackPacketCommitment' should start with _

LightClient public lightClient;
LightClient lightClient;

Check failure on line 56 in contracts/core/Dispatcher.sol

View workflow job for this annotation

GitHub Actions / lint

'lightClient' should start with _

//
// methods
Expand Down Expand Up @@ -483,7 +483,7 @@ contract Dispatcher is OwnableUpgradeable, UUPSUpgradeable, IDispatcher {
// TODO: remove below writeTimeoutPacket() function
// 1. core SC is responsible to generate timeout packet
// 2. user contract are not free to generate timeout with different criteria
// 3. [optional]: we may wish relayer to trigger timeout process, but in this case, below function won't do
// 3. [optional]: we may wish relayer to trigger timeout process, but in this case, belowunction won't do
// the job, as it doesn't have proofs.
// There is no strong reason to do this, as relayer can always do the regular `recvPacket` flow, which will
// do proper timeout generation.
Expand Down
4 changes: 0 additions & 4 deletions contracts/interfaces/IDispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ interface IDispatcher is IbcDispatcher, IbcEventsEmitter {

function sendPacket(bytes32 channelId, bytes calldata packet, uint64 timeoutTimestamp) external;

function sendPacketCommitment(address portAddress, bytes32 channelId, uint64 sequence)
external
returns (bool committed);

function acknowledgement(
IbcPacketReceiver receiver,
IbcPacket calldata packet,
Expand Down
60 changes: 31 additions & 29 deletions test/Dispatcher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,42 @@ import "../contracts/core/OpLightClient.sol";
import "./Dispatcher.base.t.sol";
import {Earth} from "../contracts/examples/Earth.sol";

abstract contract ChannelHandshakeTestSuite is Base {
abstract contract ChannelHandshakeUtils is Base {
string portId = "eth1.7E5F4552091A69125d5DfCb7b8C2659029395Bdf";
LocalEnd _local;
Mars mars;
CounterParty _remote;

function createSettings(bool localInitiate, bool isProofValid)
internal
view
returns (ChannelHandshakeSetting[4] memory)
{
Ics23Proof memory proof = isProofValid ? validProof : invalidProof;
ChannelHandshakeSetting[4] memory settings = [
ChannelHandshakeSetting(ChannelOrder.ORDERED, false, localInitiate, proof),
ChannelHandshakeSetting(ChannelOrder.UNORDERED, false, localInitiate, proof),
ChannelHandshakeSetting(ChannelOrder.ORDERED, true, localInitiate, proof),
ChannelHandshakeSetting(ChannelOrder.UNORDERED, true, localInitiate, proof)
];
return settings;
}

function createSettings2(bool isProofValid) internal view returns (ChannelHandshakeSetting[8] memory) {
// localEnd initiates
ChannelHandshakeSetting[4] memory settings1 = createSettings(true, isProofValid);
// remoteEnd initiates
ChannelHandshakeSetting[4] memory settings2 = createSettings(false, isProofValid);
ChannelHandshakeSetting[8] memory settings;
for (uint256 i = 0; i < settings1.length; i++) {
settings[i] = settings1[i];
settings[i + settings1.length] = settings2[i];
}
return settings;
}
}

abstract contract ChannelHandshakeTestSuite is ChannelHandshakeUtils {
function test_openChannel_initiator_ok() public {
ChannelHandshakeSetting[4] memory settings = createSettings(true, true);
string[2] memory versions = ["1.0", "2.0"];
Expand Down Expand Up @@ -147,34 +177,6 @@ abstract contract ChannelHandshakeTestSuite is Base {
}
}
}

function createSettings(bool localInitiate, bool isProofValid)
internal
view
returns (ChannelHandshakeSetting[4] memory)
{
Ics23Proof memory proof = isProofValid ? validProof : invalidProof;
ChannelHandshakeSetting[4] memory settings = [
ChannelHandshakeSetting(ChannelOrder.ORDERED, false, localInitiate, proof),
ChannelHandshakeSetting(ChannelOrder.UNORDERED, false, localInitiate, proof),
ChannelHandshakeSetting(ChannelOrder.ORDERED, true, localInitiate, proof),
ChannelHandshakeSetting(ChannelOrder.UNORDERED, true, localInitiate, proof)
];
return settings;
}

function createSettings2(bool isProofValid) internal view returns (ChannelHandshakeSetting[8] memory) {
// localEnd initiates
ChannelHandshakeSetting[4] memory settings1 = createSettings(true, isProofValid);
// remoteEnd initiates
ChannelHandshakeSetting[4] memory settings2 = createSettings(false, isProofValid);
ChannelHandshakeSetting[8] memory settings;
for (uint256 i = 0; i < settings1.length; i++) {
settings[i] = settings1[i];
settings[i + settings1.length] = settings2[i];
}
return settings;
}
}

contract ChannelHandshakeTest is ChannelHandshakeTestSuite {
Expand Down
Loading

0 comments on commit 2343e16

Please sign in to comment.