Skip to content

Commit

Permalink
chore: let solidity bubble up error
Browse files Browse the repository at this point in the history
  • Loading branch information
DhairyaSethi committed Apr 24, 2024
1 parent 1513565 commit 5d6bb03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
14 changes: 6 additions & 8 deletions contracts/StateReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { RLPReader } from "solidity-rlp/contracts/RLPReader.sol";

import { System } from "./System.sol";

interface IStateReceiver {
function onStateReceive(uint256, bytes calldata) external;
}

contract StateReceiver is System {
using RLPReader for bytes;
using RLPReader for RLPReader.RLPItem;
Expand All @@ -30,6 +34,7 @@ contract StateReceiver is System {
// notify state receiver contract, in a non-revert manner
if (isContract(receiver)) {
uint256 txGas = 5000000;

bytes memory data = abi.encodeWithSignature("onStateReceive(uint256,bytes)", stateId, stateData);
// solium-disable-next-line security/no-inline-assembly
assembly {
Expand All @@ -47,14 +52,7 @@ contract StateReceiver is System {
delete failedStateSyncs[stateId];

(address receiver, bytes memory stateData) = abi.decode(stateSyncData, (address, bytes));
uint256 txGas = 5000000;
bytes memory data = abi.encodeWithSignature("onStateReceive(uint256,bytes)", stateId, stateData);
bool success;
// solium-disable-next-line security/no-inline-assembly
assembly {
success := call(txGas, receiver, 0, add(data, 0x20), mload(data), 0, 0)
}
require(success, "!replay");
IStateReceiver(receiver).onStateReceive(stateId, stateData);
emit StateSyncReplay(stateId);
}

Expand Down
8 changes: 4 additions & 4 deletions test/StateReceiver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ contract('StateReceiver', async accounts => {
assert.fail('reverting receiver was able replay')
} catch (err) {
assert(
err.message.search('!replay') >= 0,
"Expected '!replay', got" + err + "' instead"
err.message.search('TestRevertingReceiver') >= 0,
"Expected 'TestRevertingReceiver', got" + err + "' instead"
)
}
})
Expand Down Expand Up @@ -261,8 +261,8 @@ contract('StateReceiver', async accounts => {
assert.fail('was able to replay again')
} catch (err) {
assert(
err.message.search('!replay') >= 0,
"Expected '!replay', got" + err + "' instead"
err.message.search('!found') >= 0,
"Expected '!found', got" + err + "' instead"
)
}
})
Expand Down

0 comments on commit 5d6bb03

Please sign in to comment.