Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
add tx index per eon
Browse files Browse the repository at this point in the history
  • Loading branch information
fredo committed Jun 21, 2024
1 parent 4e3d522 commit af9c9c7
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 20 deletions.
72 changes: 61 additions & 11 deletions gnoshcontracts/sequencer/sequencer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/ISequencer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ interface ISequencer {
function submitDecryptionProgress(bytes memory message) external;

event TransactionSubmitted(
uint64 eon,
uint64 indexed eon,
uint64 indexed txIndex,
bytes32 identityPrefix,
address sender,
bytes encryptedTransaction,
Expand Down
12 changes: 12 additions & 0 deletions src/Sequencer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ pragma solidity ^0.8.20;
import "src/ISequencer.sol";

contract Sequencer is ISequencer {

mapping(uint64 eon => uint64 txCount) private txCounters;

function submitEncryptedTransaction(
uint64 eon,
bytes32 identityPrefix,
Expand All @@ -14,16 +17,25 @@ contract Sequencer is ISequencer {
revert InsufficientFee();
}

uint64 index = txCounters[eon];
txCounters[eon] = index + 1;

emit TransactionSubmitted(
eon,
index,
identityPrefix,
msg.sender,
encryptedTransaction,
gasLimit
);

}

function submitDecryptionProgress(bytes memory message) external {
emit DecryptionProgressSubmitted(message);
}

function getTxCountForEon(uint64 eon) external view returns (uint64) {
return txCounters[eon];
}
}
39 changes: 31 additions & 8 deletions test/Sequencer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import "../src/Sequencer.sol";
contract SequencerTest is Test {
Sequencer public sequencer;

event TransactionSubmitted(
uint64 eon,
bytes32 identityPrefix,
address sender,
bytes encryptedTransaction,
uint256 gasLimit
);
event DecryptionProgressSubmitted(bytes message);

function setUp() public {
Expand All @@ -23,14 +16,16 @@ contract SequencerTest is Test {

function testSubmitTransaction() public {
uint64 eon = 5;
uint64 txIndex = 0;
bytes32 identityPrefix = hex"001122";
address sender = makeAddr("sender");
bytes memory encryptedTransaction = "aabbcc";
uint256 gasLimit = 8;

vm.expectEmit(address(sequencer));
emit TransactionSubmitted(
emit ISequencer.TransactionSubmitted(
eon,
txIndex,
identityPrefix,
sender,
encryptedTransaction,
Expand Down Expand Up @@ -72,4 +67,32 @@ contract SequencerTest is Test {
emit DecryptionProgressSubmitted(message);
sequencer.submitDecryptionProgress(message);
}

function testTxCount() public {
uint64 eon = 5;
bytes32 identityPrefix = hex"001122";
address sender = makeAddr("sender");
bytes memory encryptedTransaction = "aabbcc";
uint256 gasLimit = 8;

assertEqUint(sequencer.getTxCountForEon(eon), 0);
vm.fee(20);
hoax(sender);
sequencer.submitEncryptedTransaction{value: 160}(
eon,
identityPrefix,
encryptedTransaction,
gasLimit
);
assertEqUint(sequencer.getTxCountForEon(eon), 1);
assertEqUint(sequencer.getTxCountForEon(eon+1), 0);
sequencer.submitEncryptedTransaction{value: 160}(
eon+1,
identityPrefix,
encryptedTransaction,
gasLimit
);
assertEqUint(sequencer.getTxCountForEon(eon), 1);
assertEqUint(sequencer.getTxCountForEon(eon+1), 1);
}
}

0 comments on commit af9c9c7

Please sign in to comment.