Skip to content

Commit

Permalink
Add token send test
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Dec 11, 2024
1 parent d52cdd8 commit 370e8e2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
24 changes: 23 additions & 1 deletion contracts/schain/ExecutionLayer/ExecutionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ from "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradea
import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
import {IExecutionManager, SchainHash} from "@skalenetwork/ima-interfaces/schain/ExecutionLayer/IExecutionManager.sol";
import {IMessageProxyForSchain} from "@skalenetwork/ima-interfaces/schain/IMessageProxyForSchain.sol";
import {ExecutorId} from "@skalenetwork/ima-interfaces/schain/ExecutionLayer/IExecutor.sol";
import {RoleRequired} from "../../CommonErrors.sol";
import {MetaActionId, Protocol} from "./Protocol.sol";
import {Executor} from "./Executor.sol";

contract ExecutionManager is AccessControlEnumerableUpgradeable, IExecutionManager {
using EnumerableMap for EnumerableMap.Bytes32ToAddressMap;
Expand All @@ -49,6 +51,7 @@ contract ExecutionManager is AccessControlEnumerableUpgradeable, IExecutionManag

IMessageProxyForSchain public messageProxy;
EnumerableMap.Bytes32ToAddressMap private _remoteExecutionManagers;
EnumerableMap.Bytes32ToAddressMap private _executors;
string public testMessage;
mapping (address sender => uint256 nonce) public nonces;
mapping (MetaActionId metaActionId => MetaActionContainer) public metaActions;
Expand Down Expand Up @@ -130,6 +133,16 @@ contract ExecutionManager is AccessControlEnumerableUpgradeable, IExecutionManag
_remoteExecutionManagers.set(SchainHash.unwrap(schainHash), executionManagerAddress);
}

function setExecutor(
ExecutorId id,
Executor executorAddress
)
external
onlyController
{
_executors.set(ExecutorId.unwrap(id), address(executorAddress));
}

function execute(
Protocol.MetaAction calldata metaAction
)
Expand Down Expand Up @@ -181,6 +194,10 @@ contract ExecutionManager is AccessControlEnumerableUpgradeable, IExecutionManag
});
}

function getExecutorAddress(ExecutorId id) external view returns (Executor executor) {
return Executor(_executors.get(ExecutorId.unwrap(id)));
}

// Private

function _createMetaAction(
Expand All @@ -197,7 +214,12 @@ contract ExecutionManager is AccessControlEnumerableUpgradeable, IExecutionManag
sourceChain: SchainHash.wrap(bytes32(0)),
id: id,
status: Protocol.MetaActionStatus.EXECUTING,
metaAction: metaAction
metaAction: Protocol.MetaAction({
targetChainHash: SchainHash.wrap(bytes32(0)),
actions: "",
nextMetaAction: Protocol.encodeMetaAction(metaAction),
postActions: ""
})
});

emit MetaActionCreated(id);
Expand Down
19 changes: 18 additions & 1 deletion test/ExecutionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { deployExecutionManager } from "./utils/deploy/schain/executionManager";
import { AgentMock } from "./utils/agent/AgentMock";
import { deployMessageProxyForSchainTester } from "./utils/deploy/test/messageProxyForSchainTester";
import { assert, expect } from "chai";
import { deployERC20OnChain } from "./utils/deploy/erc20OnChain";

interface SchainSetup {
messageProxy: MessageProxyForSchain,
Expand Down Expand Up @@ -136,15 +137,31 @@ describe("ExecutionManager", () => {
}

const [sourceSchainName, targetSchainName] = [...schains.keys()];
const sourceSchainHash = ethers.id(sourceSchainName);
const targetSchainHash = ethers.id(targetSchainName);

const sourceExecutionManager = schains.get(sourceSchainName)?.executionManager;
const targetExecutionManager = schains.get(targetSchainName)?.executionManager;

assert(sourceExecutionManager);
assert(targetExecutionManager);

const token = await deployERC20OnChain("D2", "D2");
const value = ethers.parseEther("1");
await token.mint(user, value);

const send = await ethers.getContractAt(
"Send",
await sourceExecutionManager.getExecutorAddress(
ethers.id("Send")
)
);
const metaAction = await sourceExecutionManager.createMetaAction(
bytes32,(bytes32,bytes)[]
targetSchainHash,
{
executor: ethers.id("Send"),
arguments: await send.encodeArguments(user)
}
);

const executeReceipt = await (await sourceExecutionManager.connect(user).execute(
Expand Down
15 changes: 14 additions & 1 deletion test/utils/deploy/schain/executionManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers, upgrades } from "hardhat";
import { ExecutionManager, MessageProxyForSchain } from "../../../../typechain";
import { ExecutionManager, MessageProxyForSchain, Send } from "../../../../typechain";

const name = "ExecutionManager";

Expand All @@ -11,5 +11,18 @@ export async function deployExecutionManager(
factory,
[await ethers.resolveAddress(messageProxyForSchain)]
) as unknown as ExecutionManager;

await instance.grantRole(await instance.CONTROLLER_ROLE(), (await ethers.getSigners())[0])

const sendFactory = await ethers.getContractFactory("Send");
const send = await upgrades.deployProxy(
sendFactory
) as unknown as Send;

await instance.setExecutor(
await send.ID(),
send
);

return instance;
}

0 comments on commit 370e8e2

Please sign in to comment.