diff --git a/contracts/cosmwasm-vm/cw-integration/tests/test_xcall.rs b/contracts/cosmwasm-vm/cw-integration/tests/test_xcall.rs index e0c48323..bef858ea 100644 --- a/contracts/cosmwasm-vm/cw-integration/tests/test_xcall.rs +++ b/contracts/cosmwasm-vm/cw-integration/tests/test_xcall.rs @@ -96,7 +96,7 @@ pub fn call_dapp_send_call( ctx.app.execute_contract( ctx.sender.clone(), ctx.get_dapp(), - &cw_xcall_lib::xcall_msg::ExecuteMsg::SendCall { + &cw_mock_dapp_multi::msg::ExecuteMsg::SendMessageAny { to: cw_xcall_lib::network_address::NetworkAddress::from_str(&to).unwrap(), envelope, }, diff --git a/contracts/cosmwasm-vm/cw-mock-dapp-multi/src/contract.rs b/contracts/cosmwasm-vm/cw-mock-dapp-multi/src/contract.rs index 688af3f6..5c02dbf2 100644 --- a/contracts/cosmwasm-vm/cw-mock-dapp-multi/src/contract.rs +++ b/contracts/cosmwasm-vm/cw-mock-dapp-multi/src/contract.rs @@ -106,18 +106,15 @@ impl<'a> CwMockService<'a> { }); let msg = if message_type == MessageType::CallMessagePersisted as u64 { - AnyMessage::CallMessagePersisted(CallMessagePersisted { data: data.clone() }) + AnyMessage::CallMessagePersisted(CallMessagePersisted { data }) } else if message_type == MessageType::CallMessageWithRollback as u64 { if let Some(rollback) = rollback { - AnyMessage::CallMessageWithRollback(CallMessageWithRollback { - data: data.clone(), - rollback, - }) + AnyMessage::CallMessageWithRollback(CallMessageWithRollback { data, rollback }) } else { return Err(ContractError::InvalidRollbackMessage); } } else if message_type == MessageType::CallMessage as u64 { - AnyMessage::CallMessage(CallMessage { data: data.clone() }) + AnyMessage::CallMessage(CallMessage { data }) } else { return Err(ContractError::InvalidMessageType); }; diff --git a/contracts/cosmwasm-vm/cw-mock-dapp/src/contract.rs b/contracts/cosmwasm-vm/cw-mock-dapp/src/contract.rs index 50d0936c..6be19f67 100644 --- a/contracts/cosmwasm-vm/cw-mock-dapp/src/contract.rs +++ b/contracts/cosmwasm-vm/cw-mock-dapp/src/contract.rs @@ -78,14 +78,11 @@ impl<'a> CwMockService<'a> { .map_err(|_e| ContractError::ModuleAddressNotFound)?; let msg = if is_persistent { - AnyMessage::CallMessagePersisted(CallMessagePersisted { data: data.clone() }) - } else if let Some(rollback) = rollback.clone() { - AnyMessage::CallMessageWithRollback(CallMessageWithRollback { - data: data.clone(), - rollback: rollback.clone(), - }) + AnyMessage::CallMessagePersisted(CallMessagePersisted { data }) + } else if let Some(rollback) = rollback { + AnyMessage::CallMessageWithRollback(CallMessageWithRollback { data, rollback }) } else { - AnyMessage::CallMessage(CallMessage { data: data.clone() }) + AnyMessage::CallMessage(CallMessage { data }) }; let envelope = Envelope::new(msg, vec![], vec![]); diff --git a/contracts/cosmwasm-vm/cw-xcall-lib/src/message/envelope.rs b/contracts/cosmwasm-vm/cw-xcall-lib/src/message/envelope.rs index 91fa5836..f533714a 100644 --- a/contracts/cosmwasm-vm/cw-xcall-lib/src/message/envelope.rs +++ b/contracts/cosmwasm-vm/cw-xcall-lib/src/message/envelope.rs @@ -92,7 +92,7 @@ mod tests { let encoded_data = rlp::encode(&envelope).to_vec(); assert_eq!( - "e50185c483010203d087736f757263653187736f7572636532cc856465737431856465737432", + "e50085c483010203d087736f757263653187736f7572636532cc856465737431856465737432", hex::encode(&encoded_data) ); let decoded: Envelope = rlp::decode(&encoded_data).unwrap(); @@ -113,7 +113,7 @@ mod tests { let encoded_data = rlp::encode(&envelope).to_vec(); assert_eq!( - "e90289c88301020383010203d087736f757263653187736f7572636532cc856465737431856465737432", + "e90189c88301020383010203d087736f757263653187736f7572636532cc856465737431856465737432", hex::encode(&encoded_data) ); let decoded: Envelope = rlp::decode(&encoded_data).unwrap(); diff --git a/contracts/cosmwasm-vm/cw-xcall-lib/src/message/msg_type.rs b/contracts/cosmwasm-vm/cw-xcall-lib/src/message/msg_type.rs index ca2c4115..2e9b8ac4 100644 --- a/contracts/cosmwasm-vm/cw-xcall-lib/src/message/msg_type.rs +++ b/contracts/cosmwasm-vm/cw-xcall-lib/src/message/msg_type.rs @@ -2,17 +2,17 @@ use serde::Serialize; #[derive(Clone, Debug, Serialize, serde::Deserialize, PartialEq, Eq)] pub enum MessageType { - CallMessage = 1, - CallMessageWithRollback = 2, - CallMessagePersisted = 3, + CallMessage = 0, + CallMessageWithRollback = 1, + CallMessagePersisted = 2, } impl From for u8 { fn from(val: MessageType) -> Self { match val { - MessageType::CallMessage => 1, - MessageType::CallMessageWithRollback => 2, - MessageType::CallMessagePersisted => 3, + MessageType::CallMessage => 0, + MessageType::CallMessageWithRollback => 1, + MessageType::CallMessagePersisted => 2, } } } @@ -20,9 +20,9 @@ impl From for u8 { impl From for MessageType { fn from(value: u8) -> Self { match value { - 1 => MessageType::CallMessage, - 2 => MessageType::CallMessageWithRollback, - 3 => MessageType::CallMessagePersisted, + 0 => MessageType::CallMessage, + 1 => MessageType::CallMessageWithRollback, + 2 => MessageType::CallMessagePersisted, _ => panic!("unsupported message type"), } } diff --git a/contracts/cosmwasm-vm/cw-xcall/src/types/request.rs b/contracts/cosmwasm-vm/cw-xcall/src/types/request.rs index e6413dec..b5597c2a 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/types/request.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/types/request.rs @@ -191,7 +191,7 @@ mod tests { let encoded = rlp::encode(&msg); - assert_eq!("f83f8b3078312e4554482f307861aa63783030303030303030303030303030303030303030303030303030303030303030303030303031303215018474657374c0",hex::encode(encoded)); + assert_eq!("f83f8b3078312e4554482f307861aa63783030303030303030303030303030303030303030303030303030303030303030303030303031303215008474657374c0",hex::encode(encoded)); let msg = CSMessageRequest::new( NetworkAddress::from_str("0x1.ETH/0xa").unwrap(), @@ -204,7 +204,7 @@ mod tests { let encoded = rlp::encode(&msg); - assert_eq!("f84b8b3078312e4554482f307861aa63783030303030303030303030303030303030303030303030303030303030303030303030303031303215018474657374cc836162638363646583656667",hex::encode(encoded)); + assert_eq!("f84b8b3078312e4554482f307861aa63783030303030303030303030303030303030303030303030303030303030303030303030303031303215008474657374cc836162638363646583656667",hex::encode(encoded)); let msg = CSMessageRequest::new( NetworkAddress::from_str("0x1.ETH/0xa").unwrap(), @@ -217,6 +217,6 @@ mod tests { let encoded = rlp::encode(&msg); - assert_eq!("f84b8b3078312e4554482f307861aa63783030303030303030303030303030303030303030303030303030303030303030303030303031303215028474657374cc836162638363646583656667",hex::encode(encoded)); + assert_eq!("f84b8b3078312e4554482f307861aa63783030303030303030303030303030303030303030303030303030303030303030303030303031303215018474657374cc836162638363646583656667",hex::encode(encoded)); } } diff --git a/contracts/evm/library/utils/Types.sol b/contracts/evm/library/utils/Types.sol index 58842941..8f0223a3 100644 --- a/contracts/evm/library/utils/Types.sol +++ b/contracts/evm/library/utils/Types.sol @@ -21,9 +21,9 @@ library Types { int constant CS_RESULT = 2; - int constant CALL_MESSAGE_TYPE = 1; - int constant CALL_MESSAGE_ROLLBACK_TYPE = 2; - int constant PERSISTENT_MESSAGE_TYPE = 3; + int constant CALL_MESSAGE_TYPE = 0; + int constant CALL_MESSAGE_ROLLBACK_TYPE = 1; + int constant PERSISTENT_MESSAGE_TYPE = 2; /** * Legacy Code, CallRequest replaced with RollbackData diff --git a/contracts/evm/test/xcall/CallService.t.sol b/contracts/evm/test/xcall/CallService.t.sol index 6570b4ee..365f5c88 100644 --- a/contracts/evm/test/xcall/CallService.t.sol +++ b/contracts/evm/test/xcall/CallService.t.sol @@ -174,7 +174,7 @@ contract CallServiceTest is Test { vm.expectEmit(); emit CallMessageSent(address(dapp), iconDapp, 1); - Types.CSMessageRequestV2 memory request = Types.CSMessageRequestV2(ethDappAddress, dstAccount, 1, 1, data, _baseDestination); + Types.CSMessageRequestV2 memory request = Types.CSMessageRequestV2(ethDappAddress, dstAccount, 1, 0, data, _baseDestination); Types.CSMessage memory message = Types.CSMessage(Types.CS_REQUEST, request.encodeCSMessageRequestV2()); vm.expectCall(address(baseConnection), abi.encodeCall(baseConnection.sendMessage, (iconNid, Types.NAME, 0, message.encodeCSMessage()))); @@ -204,7 +204,7 @@ contract CallServiceTest is Test { vm.expectEmit(); emit CallMessageSent(address(dapp), iconDapp, 1); - Types.CSMessageRequestV2 memory request = Types.CSMessageRequestV2(ethDappAddress, dstAccount, 1, 1, data, destinations); + Types.CSMessageRequestV2 memory request = Types.CSMessageRequestV2(ethDappAddress, dstAccount, 1, 0, data, destinations); Types.CSMessage memory message = Types.CSMessage(Types.CS_REQUEST,request.encodeCSMessageRequestV2()); vm.expectCall(address(connection1), abi.encodeCall(connection1.sendMessage, (iconNid, Types.NAME, 0, message.encodeCSMessage()))); @@ -268,7 +268,7 @@ contract CallServiceTest is Test { vm.expectEmit(); emit CallMessageSent(address(dapp), iconDapp, 1); - Types.CSMessageRequestV2 memory request = Types.CSMessageRequestV2(ethDappAddress, dstAccount, 1, 2, data, new string[](0)); + Types.CSMessageRequestV2 memory request = Types.CSMessageRequestV2(ethDappAddress, dstAccount, 1, 1, data, new string[](0)); Types.CSMessage memory message = Types.CSMessage(Types.CS_REQUEST,request.encodeCSMessageRequestV2()); vm.expectCall(address(baseConnection), abi.encodeCall(baseConnection.sendMessage, (iconNid, Types.NAME, 1, message.encodeCSMessage()))); @@ -877,7 +877,7 @@ contract CallServiceTest is Test { vm.mockCall(address(connection1), abi.encodeWithSelector(connection1.getFee.selector), abi.encode(0)); vm.mockCall(address(connection2), abi.encodeWithSelector(connection2.getFee.selector), abi.encode(0)); - Types.CSMessageRequestV2 memory request = Types.CSMessageRequestV2(iconDapp, ParseAddress.toString(address(receiver)), 1, 2, data, connections); + Types.CSMessageRequestV2 memory request = Types.CSMessageRequestV2(iconDapp, ParseAddress.toString(address(receiver)), 1, 1, data, connections); Types.CSMessage memory message = Types.CSMessage(Types.CS_REQUEST,request.encodeCSMessageRequestV2()); vm.prank(address(connection1)); @@ -907,7 +907,7 @@ contract CallServiceTest is Test { defaultServiceReceiver = IDefaultCallServiceReceiver(address(0x5678)); callService.setDefaultConnection(netTo, address(baseConnection)); - Types.CSMessageRequestV2 memory request = Types.CSMessageRequestV2(iconDapp, ParseAddress.toString(address(defaultServiceReceiver)), 1, 2, data, _baseSource); + Types.CSMessageRequestV2 memory request = Types.CSMessageRequestV2(iconDapp, ParseAddress.toString(address(defaultServiceReceiver)), 1, 1, data, _baseSource); Types.CSMessage memory message = Types.CSMessage(Types.CS_REQUEST,request.encodeCSMessageRequestV2()); vm.prank(address(baseConnection)); @@ -929,7 +929,7 @@ contract CallServiceTest is Test { function testExecuteCallFailedExecution() public { bytes memory data = bytes("test"); - Types.CSMessageRequestV2 memory request = Types.CSMessageRequestV2(iconDapp, ParseAddress.toString(address(receiver)), 1, 2, data, _baseSource); + Types.CSMessageRequestV2 memory request = Types.CSMessageRequestV2(iconDapp, ParseAddress.toString(address(receiver)), 1, 1, data, _baseSource); Types.CSMessage memory message = Types.CSMessage(Types.CS_REQUEST,request.encodeCSMessageRequestV2()); vm.prank(address(baseConnection)); diff --git a/contracts/javascore/xcall-lib/src/main/java/foundation/icon/xcall/messages/CallMessage.java b/contracts/javascore/xcall-lib/src/main/java/foundation/icon/xcall/messages/CallMessage.java index 9cae7cac..cf645d3c 100644 --- a/contracts/javascore/xcall-lib/src/main/java/foundation/icon/xcall/messages/CallMessage.java +++ b/contracts/javascore/xcall-lib/src/main/java/foundation/icon/xcall/messages/CallMessage.java @@ -2,7 +2,7 @@ package foundation.icon.xcall.messages; public class CallMessage extends Message { - public static final int TYPE = 1; + public static final int TYPE = 0; private byte[] data; public CallMessage(byte[] data) { diff --git a/contracts/javascore/xcall-lib/src/main/java/foundation/icon/xcall/messages/CallMessageWithRollback.java b/contracts/javascore/xcall-lib/src/main/java/foundation/icon/xcall/messages/CallMessageWithRollback.java index e6caed97..37cc6306 100644 --- a/contracts/javascore/xcall-lib/src/main/java/foundation/icon/xcall/messages/CallMessageWithRollback.java +++ b/contracts/javascore/xcall-lib/src/main/java/foundation/icon/xcall/messages/CallMessageWithRollback.java @@ -6,7 +6,7 @@ import score.ObjectWriter; public class CallMessageWithRollback extends Message { - public static final int TYPE = 2; + public static final int TYPE = 1; private byte[] data; private byte[] rollback; public CallMessageWithRollback(byte[] data, byte[] rollback) { diff --git a/contracts/javascore/xcall-lib/src/main/java/foundation/icon/xcall/messages/PersistentMessage.java b/contracts/javascore/xcall-lib/src/main/java/foundation/icon/xcall/messages/PersistentMessage.java index 0df370fb..ffcf41a1 100644 --- a/contracts/javascore/xcall-lib/src/main/java/foundation/icon/xcall/messages/PersistentMessage.java +++ b/contracts/javascore/xcall-lib/src/main/java/foundation/icon/xcall/messages/PersistentMessage.java @@ -2,7 +2,7 @@ package foundation.icon.xcall.messages; public class PersistentMessage extends Message { - public static final int TYPE = 3; + public static final int TYPE = 2; private byte[] data; public PersistentMessage(byte[] data) { diff --git a/contracts/javascore/xcall/src/test/java/foundation/icon/xcall/CallServiceTest.java b/contracts/javascore/xcall/src/test/java/foundation/icon/xcall/CallServiceTest.java index 419ff88f..2ea35e7f 100644 --- a/contracts/javascore/xcall/src/test/java/foundation/icon/xcall/CallServiceTest.java +++ b/contracts/javascore/xcall/src/test/java/foundation/icon/xcall/CallServiceTest.java @@ -90,7 +90,7 @@ public void sendMessage_singleProtocol() { xcall.invoke(dapp.account, "sendCallMessage", ethDapp.toString(), data, null, baseSource, baseDestination); // Assert - CSMessageRequest request = new CSMessageRequest(iconDappAddress.toString(), ethDapp.account.toString(), BigInteger.ONE, 1, data, baseDestination); + CSMessageRequest request = new CSMessageRequest(iconDappAddress.toString(), ethDapp.account.toString(), BigInteger.ONE, 0, data, baseDestination); CSMessage msg = new CSMessage(CSMessage.REQUEST, request.toBytes()); verify(baseConnection.mock).sendMessage(eq(ethNid), eq(CallService.NAME), eq(BigInteger.ZERO), aryEq(msg.toBytes())); @@ -107,7 +107,7 @@ public void sendMessage_defaultProtocol() { xcall.invoke(dapp.account, "sendCallMessage", ethDapp.toString(), data); // Assert - CSMessageRequest request = new CSMessageRequest(iconDappAddress.toString(), ethDapp.account.toString(), BigInteger.ONE, 1, data, null); + CSMessageRequest request = new CSMessageRequest(iconDappAddress.toString(), ethDapp.account.toString(), BigInteger.ONE, 0, data, null); CSMessage msg = new CSMessage(CSMessage.REQUEST, request.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); @@ -139,7 +139,7 @@ public void sendMessage_multiProtocol() throws Exception { xcall.invoke(dapp.account, "sendCallMessage", ethDapp.toString(), data, null, sources, destinations); // Assert - CSMessageRequest request = new CSMessageRequest(iconDappAddress.toString(), ethDapp.account.toString(), BigInteger.ONE, 1, data, destinations); + CSMessageRequest request = new CSMessageRequest(iconDappAddress.toString(), ethDapp.account.toString(), BigInteger.ONE, 0, data, destinations); CSMessage msg = new CSMessage(CSMessage.REQUEST, request.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())); @@ -453,7 +453,7 @@ public void executeCall_multiProtocol_rollback() throws Exception { MockContract connection2 = new MockContract<>(ConnectionScoreInterface.class, Connection.class, sm, owner); String[] connections = {connection1.getAddress().toString(), connection2.getAddress().toString()}; - CSMessageRequest request = new CSMessageRequest(ethDapp.toString(), dapp.getAddress().toString(), BigInteger.ONE, 2, data, connections); + CSMessageRequest request = new CSMessageRequest(ethDapp.toString(), dapp.getAddress().toString(), BigInteger.ONE, 1, data, connections); CSMessage msg = new CSMessage(CSMessage.REQUEST, request.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());