Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated contract and test #11

Merged
merged 5 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions examples/simple/Counter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,10 @@ contract CounterTest is Test {
GmpTestTools.switchNetwork(sepoliaId);
assertEq(counter.number(), 0);

// Convert Alice address to GmpSender, passing `false` indicates
// that the sender is an EOA, not a contract
GmpSender sender = alice.toSender(false);

// Deposit funds to pay for the execution cost from Shibuya to Sepolia
sepoliaGateway.deposit{value: 1 ether}(sender, shibuyaId);
assertEq(counter.number(), 0);

// Submit a new GMP from Shibuya to Sepolia
GmpTestTools.switchNetwork(shibuyaId);
shibuyaGateway.submitMessage(address(counter), sepoliaId, 100_000, "");
uint256 deposit = shibuyaGateway.estimateMessageCost(sepoliaId, 0, 100_000);
shibuyaGateway.submitMessage{value: deposit}(address(counter), sepoliaId, 100_000, "");

// Check the counter before relaying the GMP message
GmpTestTools.switchNetwork(sepoliaId);
Expand Down
4 changes: 2 additions & 2 deletions examples/teleport-tokens/BasicERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ contract BasicERC20 is ERC20, IGmpReceiver {
/**
* @dev Teleport tokens from `msg.sender` to `recipient` in `_recipientNetwork`
*/
function teleport(address recipient, uint256 amount) external returns (bytes32 messageID) {
function teleport(address recipient, uint256 amount) external payable returns (bytes32 messageID) {
_burn(msg.sender, amount);
bytes memory message = abi.encode(TeleportCommand({from: msg.sender, to: recipient, amount: amount}));
messageID = _trustedGateway.submitMessage(address(_recipientErc20), _recipientNetwork, MSG_GAS_LIMIT, message);
messageID = _trustedGateway.submitMessage{value: msg.value}(address(_recipientErc20), _recipientNetwork, MSG_GAS_LIMIT, message);
emit OutboundTransfer(messageID, msg.sender, recipient, amount);
}

Expand Down
22 changes: 6 additions & 16 deletions examples/teleport-tokens/BasicERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,19 @@ contract GmpTestToolsTest is Test {
assertEq(address(shibuyaErc20), vm.computeCreateAddress(ALICE, 0), "unexpected shibuyaErc20 address");
assertEq(address(sepoliaErc20), vm.computeCreateAddress(BOB, 0), "unexpected sepoliaErc20 address");

///////////////////////////////////////////////////////////
// Step 3: Deposit funds to destination Gateway Contract //
///////////////////////////////////////////////////////////

// Switch to Sepolia network and Alice account
GmpTestTools.switchNetwork(SEPOLIA_NETWORK, ALICE);
// If the sender is a contract, it's address must be converted
GmpSender sender = address(shibuyaErc20).toSender(true);
// Alice deposit 1 ether to Sepolia gateway contract
SEPOLIA_GATEWAY.deposit{value: 1 ether}(sender, SHIBUYA_NETWORK);

//////////////////////////////
// Step 4: Send GMP message //
// Step 3: Send GMP message //
//////////////////////////////

// Switch to Shibuya network and Alice account
GmpTestTools.switchNetwork(SHIBUYA_NETWORK, ALICE);

// Teleport 100 tokens from Alice to to Bob's account in sepolia
// Obs: The `teleport` method internally calls `gateway.submitMessage(...)`
// Teleport 100 tokens from Alice to Bob's account in Sepolia
// Obs: The `teleport` method now calls `gateway.submitMessage(...)` with value
ManojJiSharma marked this conversation as resolved.
Show resolved Hide resolved
uint256 deposit = 2400000000000000000;
Lohann marked this conversation as resolved.
Show resolved Hide resolved
vm.expectEmit(false, true, false, true, address(shibuyaErc20));
emit BasicERC20.OutboundTransfer(bytes32(0), ALICE, BOB, 100);
bytes32 messageID = shibuyaErc20.teleport(BOB, 100);
bytes32 messageID = shibuyaErc20.teleport{value: deposit}(BOB, 100);

// Now with the `messageID`, Alice can check the message status in the destination gateway contract
// status 0: means the message is pending
Expand All @@ -95,7 +85,7 @@ contract GmpTestToolsTest is Test {
);

///////////////////////////////////////////////////
// Step 5: Wait Chronicles Relay the GMP message //
// Step 4: Wait Chronicles Relay the GMP message //
///////////////////////////////////////////////////

// The GMP hasn't been executed yet...
Expand Down