Skip to content

Commit

Permalink
feat: Change xcall btp service name to xcallM (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonAndell authored Oct 30, 2023
1 parent 6779754 commit ce37aa7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion contracts/evm/library/utils/Types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pragma solidity >=0.8.0;
*/
library Types {
// The name of CallService.
string constant NAME = "xcall-multi";
string constant NAME = "xcallM";

int constant CS_REQUEST = 1;
int constant CS_RESPONSE = 2;
Expand Down
2 changes: 0 additions & 2 deletions contracts/evm/test/xcall/CallService.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ contract CallServiceTest is Test {
string[] _baseSource;
string[] _baseDestination;

string constant xcallMulti = "xcall-multi";

event CallMessage(
string indexed _from,
string indexed _to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface CallService {
/**
* The name of CallService.
*/
String NAME = "xcall-multi";
String NAME = "xcallM";

/*======== At the source CALL_BSH ========*/
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void sendMessage_singleProtocol() {
// Assert
CSMessageRequest request = new CSMessageRequest(iconDappAddress.toString(), ethDapp.account.toString(), BigInteger.ONE, false, data, new String[]{baseEthConnection});
CSMessage msg = new CSMessage(CSMessage.REQUEST, request.toBytes());
verify(baseConnection.mock).sendMessage(eq(ethNid), eq("xcall-multi"), eq(BigInteger.ZERO), aryEq(msg.toBytes()));
verify(baseConnection.mock).sendMessage(eq(ethNid), eq(CallService.NAME), eq(BigInteger.ZERO), aryEq(msg.toBytes()));
verify(xcallSpy).CallMessageSent(dapp.getAddress(), ethDapp.toString(), BigInteger.ONE);
}

Expand All @@ -86,7 +86,7 @@ public void sendMessage_defaultProtocol() {
// Assert
CSMessageRequest request = new CSMessageRequest(iconDappAddress.toString(), ethDapp.account.toString(), BigInteger.ONE, false, data, null);
CSMessage msg = new CSMessage(CSMessage.REQUEST, request.toBytes());
verify(baseConnection.mock).sendMessage(eq(ethNid), eq("xcall-multi"), eq(BigInteger.ZERO), aryEq(msg.toBytes()));
verify(baseConnection.mock).sendMessage(eq(ethNid), eq(CallService.NAME), eq(BigInteger.ZERO), aryEq(msg.toBytes()));
verify(xcallSpy).CallMessageSent(dapp.getAddress(), ethDapp.toString(), BigInteger.ONE);
}

Expand Down Expand Up @@ -118,8 +118,8 @@ public void sendMessage_multiProtocol() throws Exception {
// Assert
CSMessageRequest request = new CSMessageRequest(iconDappAddress.toString(), ethDapp.account.toString(), BigInteger.ONE, false, data, destinations);
CSMessage msg = new CSMessage(CSMessage.REQUEST, request.toBytes());
verify(connection1.mock).sendMessage(eq(ethNid), eq("xcall-multi"), eq(BigInteger.ZERO), aryEq(msg.toBytes()));
verify(connection2.mock).sendMessage(eq(ethNid), eq("xcall-multi"), eq(BigInteger.ZERO), aryEq(msg.toBytes()));
verify(connection1.mock).sendMessage(eq(ethNid), eq(CallService.NAME), eq(BigInteger.ZERO), aryEq(msg.toBytes()));
verify(connection2.mock).sendMessage(eq(ethNid), eq(CallService.NAME), eq(BigInteger.ZERO), aryEq(msg.toBytes()));
verify(xcallSpy).CallMessageSent(dapp.getAddress(), ethDapp.toString(), BigInteger.ONE);
}

Expand All @@ -131,7 +131,7 @@ public void handleResponse_singleProtocol() {
CSMessage msg = new CSMessage(CSMessage.REQUEST, request.toBytes());

// Act
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ZERO, msg.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ZERO, msg.toBytes());

// Assert
verify(xcallSpy).CallMessage(ethDapp.toString(), dapp.getAddress().toString(), BigInteger.ONE, BigInteger.ONE, data);
Expand All @@ -146,7 +146,7 @@ public void handleResponse_singleProtocol_invalidSender() {
CSMessage msg = new CSMessage(CSMessage.REQUEST, request.toBytes());

// Act
assertThrows(Exception.class, ()->xcall.invoke(otherConnection, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ZERO, msg.toBytes()));
assertThrows(Exception.class, ()->xcall.invoke(otherConnection, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ZERO, msg.toBytes()));

// Assert
verify(xcallSpy, times(0)).CallMessage(ethDapp.toString(), dapp.getAddress().toString(), BigInteger.ONE, BigInteger.ONE, data);
Expand All @@ -161,7 +161,7 @@ public void handleResponse_defaultProtocol() {
CSMessage msg = new CSMessage(CSMessage.REQUEST, request.toBytes());

// Act
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ZERO, msg.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ZERO, msg.toBytes());

// Assert
verify(xcallSpy).CallMessage(ethDapp.toString(), dapp.getAddress().toString(), BigInteger.ONE, BigInteger.ONE, data);
Expand All @@ -177,7 +177,7 @@ public void handleResponse_defaultProtocol_invalidSender() {
Account invalidConnection = sm.createAccount();

// Act
assertThrows(Exception.class, ()-> xcall.invoke(invalidConnection, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ZERO, msg.toBytes()));
assertThrows(Exception.class, ()-> xcall.invoke(invalidConnection, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ZERO, msg.toBytes()));

// Assert
verify(xcallSpy, times(0)).CallMessage(ethDapp.toString(), dapp.getAddress().toString(), BigInteger.ONE, BigInteger.ONE, data);
Expand All @@ -195,9 +195,9 @@ public void handleResponse_multiProtocol() throws Exception {
CSMessage msg = new CSMessage(CSMessage.REQUEST, request.toBytes());

// Act
xcall.invoke(connection1.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ZERO, msg.toBytes());
xcall.invoke(connection1.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ZERO, msg.toBytes());
verify(xcallSpy, times(0)).CallMessage(ethDapp.toString(), dapp.getAddress().toString(), BigInteger.ONE, BigInteger.ONE, data);
xcall.invoke(connection2.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ZERO, msg.toBytes());
xcall.invoke(connection2.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ZERO, msg.toBytes());

// Assert
verify(xcallSpy, times(1)).CallMessage(ethDapp.toString(), dapp.getAddress().toString(), BigInteger.ONE, BigInteger.ONE, data);
Expand All @@ -209,7 +209,7 @@ public void executeCall_singleProtocol() {
byte[] data = "test".getBytes();
CSMessageRequest request = new CSMessageRequest(ethDapp.toString(), dapp.getAddress().toString(), BigInteger.ONE, false, data, new String[]{baseConnection.getAddress().toString()});
CSMessage msg = new CSMessage(CSMessage.REQUEST, request.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ZERO, msg.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ZERO, msg.toBytes());

// Act
xcall.invoke(user, "executeCall", BigInteger.ONE, data);
Expand All @@ -228,7 +228,7 @@ public void executeCall_defaultProtocol() throws Exception {
CSMessage msg = new CSMessage(CSMessage.REQUEST, request.toBytes());

xcall.invoke(owner, "setDefaultConnection", ethDapp.net(), baseConnection.getAddress());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ZERO, msg.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ZERO, msg.toBytes());

// Act
xcall.invoke(user, "executeCall", BigInteger.ONE, data);
Expand All @@ -248,8 +248,8 @@ public void executeCall_multiProtocol() throws Exception{

CSMessageRequest request = new CSMessageRequest(ethDapp.toString(), dapp.getAddress().toString(), BigInteger.ONE, false, data, connections);
CSMessage msg = new CSMessage(CSMessage.REQUEST, request.toBytes());
xcall.invoke(connection1.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ZERO, msg.toBytes());
xcall.invoke(connection2.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ZERO, msg.toBytes());
xcall.invoke(connection1.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ZERO, msg.toBytes());
xcall.invoke(connection2.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ZERO, msg.toBytes());

// Act
xcall.invoke(user, "executeCall", BigInteger.ONE, data);
Expand All @@ -269,8 +269,8 @@ public void executeCall_multiProtocol_rollback() throws Exception {

CSMessageRequest request = new CSMessageRequest(ethDapp.toString(), dapp.getAddress().toString(), BigInteger.ONE, true, data, connections);
CSMessage msg = new CSMessage(CSMessage.REQUEST, request.toBytes());
xcall.invoke(connection1.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ZERO, msg.toBytes());
xcall.invoke(connection2.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ZERO, msg.toBytes());
xcall.invoke(connection1.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ZERO, msg.toBytes());
xcall.invoke(connection2.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ZERO, msg.toBytes());

// Act
xcall.invoke(user, "executeCall", BigInteger.ONE, data);
Expand All @@ -280,8 +280,8 @@ public void executeCall_multiProtocol_rollback() throws Exception {
msg = new CSMessage(CSMessage.RESPONSE, msgRes.toBytes());

verify(dapp.mock).handleCallMessage(ethDapp.toString(), data, connections);
verify(connection1.mock).sendMessage(ethNid, "xcall-multi", BigInteger.ONE.negate(), msg.toBytes());
verify(connection2.mock).sendMessage(ethNid, "xcall-multi", BigInteger.ONE.negate(), msg.toBytes());
verify(connection1.mock).sendMessage(ethNid, CallService.NAME, BigInteger.ONE.negate(), msg.toBytes());
verify(connection2.mock).sendMessage(ethNid, CallService.NAME, BigInteger.ONE.negate(), msg.toBytes());
verify(xcallSpy).CallExecuted(BigInteger.ONE, 1, "");
}

Expand All @@ -294,7 +294,7 @@ public void executeCall_defaultProtocol_rollback() throws Exception {
CSMessage msg = new CSMessage(CSMessage.REQUEST, request.toBytes());

xcall.invoke(owner, "setDefaultConnection", ethDapp.net(), baseConnection.getAddress());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ZERO, msg.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ZERO, msg.toBytes());

// Act
xcall.invoke(user, "executeCall", BigInteger.ONE, data);
Expand All @@ -305,7 +305,7 @@ public void executeCall_defaultProtocol_rollback() throws Exception {

verify(defaultDapp.mock).handleCallMessage(ethDapp.toString(), data);
verify(xcallSpy).CallExecuted(BigInteger.ONE, 1, "");
verify(baseConnection.mock).sendMessage(ethNid, "xcall-multi", BigInteger.ONE.negate(), msg.toBytes());
verify(baseConnection.mock).sendMessage(ethNid, CallService.NAME, BigInteger.ONE.negate(), msg.toBytes());
}

@Test
Expand All @@ -314,15 +314,15 @@ public void executeCall_failedExecution() {
byte[] data = "test".getBytes();
CSMessageRequest request = new CSMessageRequest(ethDapp.toString(), dapp.getAddress().toString(), BigInteger.ONE, true, data, new String[]{baseConnection.getAddress().toString()});
CSMessage msg = new CSMessage(CSMessage.REQUEST, request.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ZERO, msg.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ZERO, msg.toBytes());
// Act
doThrow(new UserRevertedException()).when(dapp.mock).handleCallMessage(ethDapp.toString(), data, new String[]{baseConnection.getAddress().toString()});
xcall.invoke(user, "executeCall", BigInteger.ONE, data);

// Assert
CSMessageResponse msgRes = new CSMessageResponse(BigInteger.ONE, CSMessageResponse.FAILURE);
msg = new CSMessage(CSMessage.RESPONSE, msgRes.toBytes());
verify(baseConnection.mock).sendMessage(ethNid, "xcall-multi", BigInteger.ONE.negate(), msg.toBytes());
verify(baseConnection.mock).sendMessage(ethNid, CallService.NAME, BigInteger.ONE.negate(), msg.toBytes());
verify(xcallSpy).CallExecuted(BigInteger.ONE, 0, "score.RevertedException");
}

Expand All @@ -337,7 +337,7 @@ public void rollback_singleProtocol() {
// Act
CSMessageResponse msgRes = new CSMessageResponse(BigInteger.ONE, CSMessageResponse.FAILURE);
CSMessage msg = new CSMessage(CSMessage.RESPONSE, msgRes.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ONE, msg.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ONE, msg.toBytes());

// Assert
verify(xcallSpy).ResponseMessage(BigInteger.ONE, CSMessageResponse.FAILURE);
Expand All @@ -356,7 +356,7 @@ public void rollback_defaultProtocol() {
// Act
CSMessageResponse msgRes = new CSMessageResponse(BigInteger.ONE, CSMessageResponse.FAILURE);
CSMessage msg = new CSMessage(CSMessage.RESPONSE, msgRes.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ONE, msg.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ONE, msg.toBytes());

// Assert
verify(xcallSpy).ResponseMessage(BigInteger.ONE, CSMessageResponse.FAILURE);
Expand All @@ -376,7 +376,7 @@ public void rollback_defaultProtocol_invalidSender() {
// Act
CSMessageResponse msgRes = new CSMessageResponse(BigInteger.ONE, CSMessageResponse.FAILURE);
CSMessage msg = new CSMessage(CSMessage.RESPONSE, msgRes.toBytes());
assertThrows(Exception.class, ()-> xcall.invoke(invalidConnection, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ONE, msg.toBytes()));
assertThrows(Exception.class, ()-> xcall.invoke(invalidConnection, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ONE, msg.toBytes()));

// Assert
verify(xcallSpy, times(0)).ResponseMessage(BigInteger.ONE, CSMessageResponse.FAILURE);
Expand All @@ -402,9 +402,9 @@ public void rollback_multiProtocol() throws Exception {
// Act
CSMessageResponse msgRes = new CSMessageResponse(BigInteger.ONE, CSMessageResponse.FAILURE);
CSMessage msg = new CSMessage(CSMessage.RESPONSE, msgRes.toBytes());
xcall.invoke(connection1.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ONE, msg.toBytes());
xcall.invoke(connection1.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ONE, msg.toBytes());
verify(xcallSpy, times(0)).ResponseMessage(BigInteger.ONE, CSMessageResponse.FAILURE);
xcall.invoke(connection2.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ONE, msg.toBytes());
xcall.invoke(connection2.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ONE, msg.toBytes());

// Assert
verify(xcallSpy).ResponseMessage(BigInteger.ONE, CSMessageResponse.FAILURE);
Expand All @@ -422,7 +422,7 @@ public void rollback_success() throws Exception {
// Act
CSMessageResponse msgRes = new CSMessageResponse(BigInteger.ONE, CSMessageResponse.SUCCESS);
CSMessage msg = new CSMessage(CSMessage.RESPONSE, msgRes.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ONE, msg.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ONE, msg.toBytes());

// Assert
verify(xcallSpy).ResponseMessage(BigInteger.ONE, CSMessageResponse.SUCCESS);
Expand All @@ -443,7 +443,7 @@ public void executeRollback_singleProtocol() {

CSMessageResponse msgRes = new CSMessageResponse(BigInteger.ONE, CSMessageResponse.FAILURE);
CSMessage msg = new CSMessage(CSMessage.RESPONSE, msgRes.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ONE, msg.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ONE, msg.toBytes());

// Act
xcall.invoke(user, "executeRollback", BigInteger.ONE);
Expand All @@ -467,7 +467,7 @@ public void executeRollback_defaultProtocol() throws Exception {

CSMessageResponse msgRes = new CSMessageResponse(BigInteger.ONE, CSMessageResponse.FAILURE);
CSMessage msg = new CSMessage(CSMessage.RESPONSE, msgRes.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ONE, msg.toBytes());
xcall.invoke(baseConnection.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ONE, msg.toBytes());

// Act
xcall.invoke(user, "executeRollback", BigInteger.ONE);
Expand Down Expand Up @@ -496,8 +496,8 @@ public void executeRollback_multiProtocol() throws Exception {
xcall.invoke(dapp.account, "sendCallMessage", ethDapp.toString(), data, rollback, sources, destinations);
CSMessageResponse msgRes = new CSMessageResponse(BigInteger.ONE, CSMessageResponse.FAILURE);
CSMessage msg = new CSMessage(CSMessage.RESPONSE, msgRes.toBytes());
xcall.invoke(connection1.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ONE, msg.toBytes());
xcall.invoke(connection2.account, "handleBTPMessage", ethNid, "xcall-multi", BigInteger.ONE, msg.toBytes());
xcall.invoke(connection1.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ONE, msg.toBytes());
xcall.invoke(connection2.account, "handleBTPMessage", ethNid, CallService.NAME, BigInteger.ONE, msg.toBytes());

// Act
xcall.invoke(user, "executeRollback", BigInteger.ONE);
Expand Down
9 changes: 5 additions & 4 deletions docs/adr/xcall.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ CallRequest {
MAX_DATA_SIZE: 2048
MAX_ROLLBACK_SIZE: 1024
NID: <networkId>
SVC_NAME = xcallM
sn: <current send message sequence>
reqId: <current incoming message sequence>
Expand Down Expand Up @@ -466,11 +467,11 @@ payable external function sendCallMessage(String _to,
if _sources == []:
src = defaultConnection[dst.net()]
fee = src->getFee(dst.net(), needResponse)
src->sendMessage(fee, dst.net(), "xcall-multi", sendSn, msg)
src->sendMessage(fee, dst.net(), SVC_NAME, sendSn, msg)
else:
for src in sources:
fee = src->getFee(dst.net(), needResponse)
src->sendMessage(fee, dst.net(), "xcall-multi", sendSn, msg)
src->sendMessage(fee, dst.net(), SVC_NAME, sendSn, msg)
remaningBalance = getBalance();
Expand Down Expand Up @@ -629,10 +630,10 @@ external function executeCall(Integer _reqId, byte[] _data) {
msg = CSMessage(CSMessage.RESPONSE, response.toBytes());
if req.protocols == []:
protocol = defaultConnection[from.net()]
protocol->sendMessage(from.net(), "xcall-multi", sn, msg.toBytes())
protocol->sendMessage(from.net(), SVC_NAME, sn, msg.toBytes())
else:
for (String protocol : req.protocols):
protocol->sendMessage(from.net(), "xcall-multi", sn, msg.toBytes())
protocol->sendMessage(from.net(), SVC_NAME, sn, msg.toBytes())
}

```
Expand Down

0 comments on commit ce37aa7

Please sign in to comment.