Skip to content

Commit

Permalink
clean up IntegrationTest
Browse files Browse the repository at this point in the history
  • Loading branch information
gjermundgaraba committed Nov 24, 2024
1 parent 965faec commit 2977ae9
Showing 1 changed file with 32 additions and 43 deletions.
75 changes: 32 additions & 43 deletions test/IntegrationTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,21 @@ contract IntegrationTest is Test {
uint32 sequence = ics20Transfer.sendTransfer(transferMsg);
assertEq(sequence, 1);

bytes memory value = ICS20Lib.encodePayload(
ICS20Lib.FungibleTokenPacketData({
denom: erc20AddressStr,
sender: senderStr,
receiver: receiverStr,
amount: transferAmount,
memo: "memo"
})
);
ICS20Lib.FungibleTokenPacketData memory packetData = ICS20Lib.FungibleTokenPacketData({
denom: erc20AddressStr,
sender: senderStr,
receiver: receiverStr,
amount: transferAmount,
memo: "memo"
});

IICS26RouterMsgs.Payload[] memory packetPayloads = new IICS26RouterMsgs.Payload[](1);
packetPayloads[0] = IICS26RouterMsgs.Payload({
sourcePort: "transfer",
destPort: "transfer",
version: ICS20Lib.ICS20_VERSION,
encoding: ICS20Lib.ICS20_ENCODING,
value: value
value: ICS20Lib.encodePayload(packetData)
});
IICS26RouterMsgs.Packet memory packet = IICS26RouterMsgs.Packet({
sequence: sequence,
Expand Down Expand Up @@ -367,7 +365,6 @@ contract IntegrationTest is Test {
memo: "backmemo"
});

// For the packet back we pretend this is ibc-go and that the timeout is in nanoseconds
IICS26RouterMsgs.Payload[] memory payloads = new IICS26RouterMsgs.Payload[](1);
payloads[0] = IICS26RouterMsgs.Payload({
sourcePort: ICS20Lib.DEFAULT_PORT_ID,
Expand Down Expand Up @@ -449,22 +446,20 @@ contract IntegrationTest is Test {
senderStr = "cosmos1mhmwgrfrcrdex5gnr0vcqt90wknunsxej63feh";
string memory receivedDenom = string(abi.encodePacked("transfer/", counterpartyClient, "/", erc20AddressStr));

// For the packet back we pretend this is ibc-go and that the timeout is in nanoseconds
ICS20Lib.FungibleTokenPacketData memory receivePacketData = ICS20Lib.FungibleTokenPacketData({
denom: receivedDenom,
sender: senderStr,
receiver: receiverStr,
amount: transferAmount,
memo: "backmemo"
});
IICS26RouterMsgs.Payload[] memory payloads = new IICS26RouterMsgs.Payload[](1);
payloads[0] = IICS26RouterMsgs.Payload({
sourcePort: ICS20Lib.DEFAULT_PORT_ID,
destPort: ICS20Lib.DEFAULT_PORT_ID,
version: ICS20Lib.ICS20_VERSION,
encoding: ICS20Lib.ICS20_ENCODING,
value: ICS20Lib.encodePayload(
ICS20Lib.FungibleTokenPacketData({
denom: receivedDenom,
sender: senderStr,
receiver: receiverStr,
amount: transferAmount,
memo: "backmemo"
})
)
value: ICS20Lib.encodePayload(receivePacketData)
});
packet = IICS26RouterMsgs.Packet({
sequence: 1,
Expand Down Expand Up @@ -525,22 +520,20 @@ contract IntegrationTest is Test {
senderStr = "cosmos1mhmwgrfrcrdex5gnr0vcqt90wknunsxej63feh";
string memory receivedDenom = string(abi.encodePacked("transfer/", counterpartyClient, "/", erc20AddressStr));

// For the packet back we pretend this is ibc-go and that the timeout is in nanoseconds
ICS20Lib.FungibleTokenPacketData memory receivePacketData = ICS20Lib.FungibleTokenPacketData({
denom: receivedDenom,
sender: senderStr,
receiver: receiverStr,
amount: transferAmount,
memo: "backmemo"
});
IICS26RouterMsgs.Payload[] memory payloads = new IICS26RouterMsgs.Payload[](1);
payloads[0] = IICS26RouterMsgs.Payload({
sourcePort: ICS20Lib.DEFAULT_PORT_ID,
destPort: ICS20Lib.DEFAULT_PORT_ID,
version: ICS20Lib.ICS20_VERSION,
encoding: ICS20Lib.ICS20_ENCODING,
value: ICS20Lib.encodePayload(
ICS20Lib.FungibleTokenPacketData({
denom: receivedDenom,
sender: senderStr,
receiver: receiverStr,
amount: transferAmount,
memo: "backmemo"
})
)
value: ICS20Lib.encodePayload(receivePacketData)
});
packet = IICS26RouterMsgs.Packet({
sequence: 1,
Expand Down Expand Up @@ -581,8 +574,6 @@ contract IntegrationTest is Test {
receiver = makeAddr("receiver_of_foreign_denom");
receiverStr = Strings.toHexString(receiver);

// For the packet back we pretend this is ibc-go and that the timeout is in nanoseconds

ICS20Lib.FungibleTokenPacketData memory receivePacketData = ICS20Lib.FungibleTokenPacketData({
denom: foreignDenom,
sender: senderStr,
Expand Down Expand Up @@ -1214,23 +1205,21 @@ contract IntegrationTest is Test {
senderStr = "cosmos1mhmwgrfrcrdex5gnr0vcqt90wknunsxej63feh";
string memory ibcDenom = string(abi.encodePacked("transfer/", counterpartyClient, "/", erc20AddressStr));

ICS20Lib.FungibleTokenPacketData memory pd;
pd.denom = ibcDenom;
pd.amount = transferAmount;
pd.sender = senderStr;
pd.receiver = receiverStr;
pd.memo = "backmemo";

bytes memory transferPayload = ICS20Lib.encodePayload(pd);

ICS20Lib.FungibleTokenPacketData memory receivePacketData = ICS20Lib.FungibleTokenPacketData({
denom: ibcDenom,
sender: senderStr,
receiver: receiverStr,
amount: transferAmount,
memo: "backmemo"
});
uint64 timeoutTimestamp = uint64(block.timestamp - 1);
IICS26RouterMsgs.Payload[] memory payloads = new IICS26RouterMsgs.Payload[](1);
payloads[0] = IICS26RouterMsgs.Payload({
sourcePort: ICS20Lib.DEFAULT_PORT_ID,
destPort: ICS20Lib.DEFAULT_PORT_ID,
version: ICS20Lib.ICS20_VERSION,
encoding: ICS20Lib.ICS20_ENCODING,
value: transferPayload
value: ICS20Lib.encodePayload(receivePacketData)
});
packet = IICS26RouterMsgs.Packet({
sequence: 1,
Expand Down

0 comments on commit 2977ae9

Please sign in to comment.