Skip to content

Commit

Permalink
Merge branch 'main' into candidate-peers
Browse files Browse the repository at this point in the history
  • Loading branch information
renancloudwalk authored Jun 4, 2024
2 parents 377bae3 + f3a9beb commit d6a9201
Show file tree
Hide file tree
Showing 23 changed files with 367 additions and 66 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/_setup-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
timeout-minutes: 35
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Cache Cargo Registry and Target Directory
uses: actions/[email protected]
Expand All @@ -46,10 +46,10 @@ jobs:
run: sudo apt-get install -y protobuf-compiler

- name: Set up Just
uses: extractions/setup-just@v1
uses: extractions/setup-just@v2

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: .tool-versions

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/check-features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Cache Cargo Registry and Target Directory
uses: actions/[email protected]
Expand All @@ -56,7 +56,7 @@ jobs:
run: sudo apt-get install -y protobuf-compiler

- name: Set up Just
uses: extractions/setup-just@v1
uses: extractions/setup-just@v2

- name: Set up Test Dependencies
if: ${{ steps.cache-cargo.outputs.cache-hit != 'true' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/comment-tag-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Rust
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
continue-on-error: true
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Ruby
uses: ruby/setup-ruby@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/doc-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Cache Cargo Registry and Target Directory
uses: actions/[email protected]
Expand All @@ -51,7 +51,7 @@ jobs:
run: sudo apt-get install -y protobuf-compiler

- name: Set up Just
uses: extractions/setup-just@v1
uses: extractions/setup-just@v2

- name: Test docs
run: just test-doc
4 changes: 2 additions & 2 deletions .github/workflows/docs-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Cache Cargo Registry and Target Directory
uses: actions/[email protected]
Expand All @@ -49,7 +49,7 @@ jobs:
run: sudo apt-get install -y protobuf-compiler

- name: Set up Just
uses: extractions/setup-just@v1
uses: extractions/setup-just@v2

- name: Generate docs
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/e2e-contracts-postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Cache Cargo Registry and Target Directory
uses: actions/[email protected]
Expand All @@ -63,10 +63,10 @@ jobs:
run: sudo apt-get install -y protobuf-compiler

- name: Set up Just
uses: extractions/setup-just@v1
uses: extractions/setup-just@v2

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: .tool-versions

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/e2e-contracts-rocks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Cache Cargo Registry and Target Directory
uses: actions/[email protected]
Expand All @@ -63,10 +63,10 @@ jobs:
run: sudo apt-get install -y protobuf-compiler

- name: Set up Just
uses: extractions/setup-just@v1
uses: extractions/setup-just@v2

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: .tool-versions

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/e2e-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Cache Cargo Registry and Target Directory
uses: actions/[email protected]
Expand All @@ -63,10 +63,10 @@ jobs:
run: sudo apt-get install -y protobuf-compiler

- name: Set up Just
uses: extractions/setup-just@v1
uses: extractions/setup-just@v2

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: .tool-versions

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/int-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Cache Cargo Registry and Target Directory
uses: actions/[email protected]
Expand All @@ -59,7 +59,7 @@ jobs:
run: sudo apt-get install -y protobuf-compiler

- name: Set up Just
uses: extractions/setup-just@v1
uses: extractions/setup-just@v2

- name: Integration tests
run: just test-int
4 changes: 2 additions & 2 deletions .github/workflows/lint-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Cache Cargo Registry and Target Directory
uses: actions/[email protected]
Expand All @@ -57,7 +57,7 @@ jobs:
run: sudo apt-get install -y protobuf-compiler

- name: Set up Just
uses: extractions/setup-just@v1
uses: extractions/setup-just@v2

- name: Just lint-check
run: just lint-check -2024-01-01
4 changes: 2 additions & 2 deletions .github/workflows/outdated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ jobs:
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Rust
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

- name: Set up Just
uses: extractions/setup-just@v1
uses: extractions/setup-just@v2

- name: Check outdated
run: just outdated > outdated.txt
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Cache Cargo Registry and Target Directory
uses: actions/[email protected]
Expand All @@ -58,7 +58,7 @@ jobs:
run: sudo apt-get install -y protobuf-compiler

- name: Set up Just
uses: extractions/setup-just@v1
uses: extractions/setup-just@v2

- name: Unit tests
run: just test-unit
47 changes: 47 additions & 0 deletions e2e/contracts/TestContractDenseStorage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract TestContractDenseStorage {

struct Record {
uint16 field16;
uint16 reserve;
uint32 field32;
uint64 field64;
uint128 field128;
}

mapping(address => Record) public records;

/// @dev Changes fields of the record for an account.
/// @param changeOfField16 The value to change of the appropriate fields of the record.
/// @param changeOfField32 The value to change of the appropriate fields of the record.
/// @param changeOfField64 The value to change of the appropriate fields of the record.
/// @param changeOfField128 The value to change of the appropriate fields of the record.
function change(
address account,
int256 changeOfField16,
int256 changeOfField32,
int256 changeOfField64,
int256 changeOfField128
) public {
Record storage record = records[account];

record.field16 = uint16(uint256(int256(uint256(record.field16)) + changeOfField16));
record.field32 = uint32(uint256(int256(uint256(record.field32)) + changeOfField32));
record.field64 = uint64(uint256(int256(uint256(record.field64)) + changeOfField64));
record.field128 = uint128(uint256(int256(uint256(record.field128)) + changeOfField128));
}

/// @dev Sets the exact field values of the record for an an account.
/// @param newRecord The new content of the record for the account.
function set(address account, Record calldata newRecord) public {
records[account] = newRecord;
}

/// @dev Gets the record of an account.
/// @return The record of the account.
function get(address account) public view returns (Record memory) {
return records[account];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Account, ALICE, BOB, randomAccounts } from "../helpers/account";
import { deployTestContractDenseStorage, sendRawTransactions, } from "../helpers/rpc";
import {
AccountRecord,
applyRecordChange,
compareRecords,
defineRecordChange,
initialRecord,
inverseRecordChange,
prepareSignedTxOfRecordChange
} from "../helpers/contract-dense-storage";

describe("Transaction: parallel for the 'TestContractDenseStorage' contract", async () => {
it("Parallel transactions execute properly when no reverts are expected", async () => {
const contract = await deployTestContractDenseStorage();

const expectedRecords: Record<string, AccountRecord> = {};
expectedRecords[ALICE.address] = { ...initialRecord };
expectedRecords[BOB.address] = { ...initialRecord };

// Set initial records
await contract.set(ALICE.address, expectedRecords[ALICE.address]);
await contract.set(BOB.address, expectedRecords[BOB.address]);


// Prepare a pair of transactions: one for Alice and another for Bob
const txCountPerUser = 32;
const senders: Account[] = randomAccounts(txCountPerUser * 2);
const signedTxs: string[] = [];
for (let txIndexPerUser = 0; txIndexPerUser < txCountPerUser; ++txIndexPerUser) {
const recordChange1 = defineRecordChange(txIndexPerUser);
const recordChange2 = inverseRecordChange(recordChange1);
applyRecordChange(expectedRecords[ALICE.address], recordChange1);
applyRecordChange(expectedRecords[BOB.address], recordChange2);

const sender1 = senders[txIndexPerUser * 2];
const sender2 = senders[txIndexPerUser * 2 + 1];
const signTx1: string = await prepareSignedTxOfRecordChange(contract, sender1, ALICE, recordChange1);
const signTx2: string = await prepareSignedTxOfRecordChange(contract, sender2, BOB, recordChange2);

signedTxs.push(signTx1);
signedTxs.push(signTx2);
}

// Send transactions in parallel
await sendRawTransactions(signedTxs);

// Verify
compareRecords(await contract.get(ALICE.address), expectedRecords[ALICE.address]);
compareRecords(await contract.get(BOB.address), expectedRecords[BOB.address]);
});
});
8 changes: 4 additions & 4 deletions e2e/test/automine/e2e-tx-parallel-contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";

import { TestContractBalances, TestContractCounter } from "../typechain-types";
import { TestContractBalances, TestContractCounter } from "../../typechain-types";
import { ALICE, BOB, CHARLIE, randomAccounts } from "../helpers/account";
import {
TX_PARAMS,
Expand All @@ -12,7 +12,7 @@ import {
} from "../helpers/rpc";

describe("Transaction: parallel TestContractBalances", async () => {
var _contract: TestContractBalances;
let _contract: TestContractBalances;

it("Resets blockchain", async () => {
await sendReset();
Expand Down Expand Up @@ -94,7 +94,7 @@ describe("Transaction: parallel TestContractBalances", async () => {
});

describe("Transaction: parallel TestContractCounter", async () => {
var _contract: TestContractCounter;
let _contract: TestContractCounter;

it("Resets blockchain", async () => {
await sendReset();
Expand All @@ -112,7 +112,7 @@ describe("Transaction: parallel TestContractCounter", async () => {
const incSender = ALICE;
const doubleSender = BOB;

// send pair of inc and double requests
// send a pair of inc and double requests
for (let i = 0; i < 20; i++) {
// calculate expected double counter
const doubleCounter = Number(await _contract.getDoubleCounter());
Expand Down
8 changes: 4 additions & 4 deletions e2e/test/automine/e2e-tx-serial-contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";

import { TestContractBalances } from "../typechain-types";
import { TestContractBalances } from "../../typechain-types";
import { CHARLIE } from "../helpers/account";
import {
calculateSlotPosition,
Expand All @@ -23,8 +23,8 @@ const CONTRACT_TOPIC_ADD = "0x2728c9d3205d667bbc0eefdfeda366261b4d021949630c047f
const CONTRACT_TOPIC_SUB = "0xf9c652bcdb0eed6299c6a878897eb3af110dbb265833e7af75ad3d2c2f4a980c";

describe("Transaction: serial TestContractBalances", () => {
var _contract: TestContractBalances;
var _block: number;
let _contract: TestContractBalances;
let _block: number;

it("Resets blockchain", async () => {
await sendReset();
Expand Down Expand Up @@ -91,7 +91,7 @@ describe("Transaction: serial TestContractBalances", () => {
const transaction: Transaction = await send("eth_getTransactionByHash", [deploymentTransactionHash]);

expect(transaction.from).eq(CHARLIE.address, "tx.from");
expect(transaction.to).eq(null), "tx.to";
expect(transaction.to).eq(null, "tx.to");
expect(transaction.value).eq('0x0', "tx.value");
expect(transaction.gas).match(HEX_PATTERN, "tx.gas format");
expect(transaction.gasPrice).match(HEX_PATTERN, "tx.gasPrice format");
Expand Down
Loading

0 comments on commit d6a9201

Please sign in to comment.