Skip to content

Commit

Permalink
fix: set sn to 0 if response not required
Browse files Browse the repository at this point in the history
  • Loading branch information
redlarva committed Nov 8, 2023
1 parent 0d761ba commit 6beef58
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions contracts/evm/contracts/xcall/CallService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,11 @@ contract CallService is IBSH, ICallService, IFeeManage, Initializable {
(string memory netTo, string memory dstAccount) = _to.parseNetworkAddress();
string memory from = nid.networkAddress(msg.sender.toString());
uint256 sn = getNextSn();
int256 msgSn = int256(sn);
if (needResponse) {
requests[sn] = Types.CallRequest(msg.sender, netTo, sources, _rollback, false);
}
int256 msgSn = 0;
if (needResponse) {
requests[sn] = Types.CallRequest(msg.sender, netTo, sources, _rollback, false);
msgSn = int256(sn);
}
Types.CSMessageRequest memory reqMsg = Types.CSMessageRequest(
from, dstAccount, sn, needResponse, _data, destinations);
bytes memory _msg = reqMsg.encodeCSMessageRequest();
Expand Down
6 changes: 3 additions & 3 deletions contracts/evm/test/xcall/CallService.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ contract CallServiceTest is Test {
Types.CSMessageRequest memory request = Types.CSMessageRequest(ethDappAddress, dstAccount, 1, false, data, _baseDestination);
Types.CSMessage memory message = Types.CSMessage(Types.CS_REQUEST, request.encodeCSMessageRequest());

vm.expectCall(address(baseConnection), abi.encodeCall(baseConnection.sendMessage, (iconNid, Types.NAME, 1, message.encodeCSMessage())));
vm.expectCall(address(baseConnection), abi.encodeCall(baseConnection.sendMessage, (iconNid, Types.NAME, 0, message.encodeCSMessage())));

uint256 sn = callService.sendCallMessage{value: 0 ether}(iconDapp, data, rollbackData, _baseSource, _baseDestination);
assertEq(sn, 1);
Expand Down Expand Up @@ -193,8 +193,8 @@ contract CallServiceTest is Test {
Types.CSMessageRequest memory request = Types.CSMessageRequest(ethDappAddress, dstAccount, 1, false, data, destinations);
Types.CSMessage memory message = Types.CSMessage(Types.CS_REQUEST,request.encodeCSMessageRequest());

vm.expectCall(address(connection1), abi.encodeCall(connection1.sendMessage, (iconNid, Types.NAME, 1, message.encodeCSMessage())));
vm.expectCall(address(connection2), abi.encodeCall(connection2.sendMessage, (iconNid, Types.NAME, 1, message.encodeCSMessage())));
vm.expectCall(address(connection1), abi.encodeCall(connection1.sendMessage, (iconNid, Types.NAME, 0, message.encodeCSMessage())));
vm.expectCall(address(connection2), abi.encodeCall(connection2.sendMessage, (iconNid, Types.NAME, 0, message.encodeCSMessage())));

vm.prank(address(dapp));
uint256 sn = callService.sendCallMessage{value: 0 ether}(iconDapp, data, rollbackData, sources, destinations);
Expand Down

0 comments on commit 6beef58

Please sign in to comment.