[executor/contract] add get methods and tests (#1260)
* add methods and tests * add sequence check
This commit is contained in:
parent
343c784dd1
commit
11c1fa7101
|
@ -65,7 +65,7 @@ contract Executor {
|
||||||
// whose payload is a serialized GovernanceInstruction.
|
// whose payload is a serialized GovernanceInstruction.
|
||||||
function execute(
|
function execute(
|
||||||
bytes memory encodedVm
|
bytes memory encodedVm
|
||||||
) public returns (bytes memory response) {
|
) public payable returns (bytes memory response) {
|
||||||
IWormhole.VM memory vm = verifyGovernanceVM(encodedVm);
|
IWormhole.VM memory vm = verifyGovernanceVM(encodedVm);
|
||||||
|
|
||||||
GovernanceInstruction memory gi = parseGovernanceInstruction(
|
GovernanceInstruction memory gi = parseGovernanceInstruction(
|
||||||
|
@ -179,4 +179,16 @@ contract Executor {
|
||||||
encodedInstruction.length - index
|
encodedInstruction.length - index
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getOwnerChainId() public view returns (uint64) {
|
||||||
|
return ownerEmitterChainId;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getOwnerEmitterAddress() public view returns (bytes32) {
|
||||||
|
return ownerEmitterAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLastExecutedSequence() public view returns (uint64) {
|
||||||
|
return lastExecutedSequence;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,6 @@ contract ExecutorUpgradable is
|
||||||
}
|
}
|
||||||
|
|
||||||
function version() public pure returns (string memory) {
|
function version() public pure returns (string memory) {
|
||||||
return "0.1.0";
|
return "0.1.1";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,16 @@ contract ExecutorTest is Test, WormholeTestUtils {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testExecutorOwnerChainId() public {
|
||||||
|
uint chainId = executor.getOwnerChainId();
|
||||||
|
assertEq(chainId, OWNER_CHAIN_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testExecutorOwnerEmitterAddress() public {
|
||||||
|
bytes32 ownerEmitterAddress = executor.getOwnerEmitterAddress();
|
||||||
|
assertEq(ownerEmitterAddress, OWNER_EMITTER);
|
||||||
|
}
|
||||||
|
|
||||||
function testExecutorOwner() public {
|
function testExecutorOwner() public {
|
||||||
assertEq(address(executor), executor.owner());
|
assertEq(address(executor), executor.owner());
|
||||||
}
|
}
|
||||||
|
@ -123,6 +133,58 @@ contract ExecutorTest is Test, WormholeTestUtils {
|
||||||
executor.execute(vaa);
|
executor.execute(vaa);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testLastExecutedSequenceUpdateOnSucceed() public {
|
||||||
|
callable.reset();
|
||||||
|
|
||||||
|
uint32 c = callable.fooCount();
|
||||||
|
uint oldSequence = executor.getLastExecutedSequence();
|
||||||
|
uint64 sequence = 1;
|
||||||
|
assertEq(callable.lastCaller(), address(bytes20(0)));
|
||||||
|
testExecute(
|
||||||
|
address(callable),
|
||||||
|
abi.encodeWithSelector(ICallable.foo.selector),
|
||||||
|
sequence,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
uint newSequence = executor.getLastExecutedSequence();
|
||||||
|
|
||||||
|
assertGt(newSequence, oldSequence);
|
||||||
|
assertEq(newSequence, sequence);
|
||||||
|
assertEq(callable.fooCount(), c + 1);
|
||||||
|
assertEq(callable.lastCaller(), address(executor));
|
||||||
|
// Sanity check to make sure the check above is meaningful.
|
||||||
|
assert(address(executor) != address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLastExecutedSequenceNoChangeOnFail() public {
|
||||||
|
uint oldSequence = executor.getLastExecutedSequence();
|
||||||
|
|
||||||
|
bytes memory payload = abi.encodePacked(
|
||||||
|
uint32(0x5054474d),
|
||||||
|
PythGovernanceInstructions.GovernanceModule.EvmExecutor,
|
||||||
|
Executor.ExecutorAction.Execute,
|
||||||
|
CHAIN_ID,
|
||||||
|
address(executor),
|
||||||
|
address(callable),
|
||||||
|
uint(0),
|
||||||
|
abi.encodeWithSelector(ICallable.reverts.selector)
|
||||||
|
);
|
||||||
|
|
||||||
|
bytes memory vaa = generateVaa(
|
||||||
|
uint32(block.timestamp),
|
||||||
|
OWNER_CHAIN_ID,
|
||||||
|
OWNER_EMITTER,
|
||||||
|
1,
|
||||||
|
payload,
|
||||||
|
NUM_SIGNERS
|
||||||
|
);
|
||||||
|
|
||||||
|
vm.expectRevert("call should revert");
|
||||||
|
executor.execute(vaa);
|
||||||
|
uint newSequence = executor.getLastExecutedSequence();
|
||||||
|
assertEq(newSequence, oldSequence);
|
||||||
|
}
|
||||||
|
|
||||||
function testCallSucceeds() public {
|
function testCallSucceeds() public {
|
||||||
callable.reset();
|
callable.reset();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue