Skip to content

Commit

Permalink
remove versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
gretzke committed Jul 1, 2024
1 parent 6ed2d53 commit 58d15c2
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 142 deletions.
15 changes: 4 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
- [Code Style](#code-style)
- [Interfaces](#interfaces)
- [NatSpec \& Comments](#natspec--comments)
- [Versioning](#versioning)
- [Testing](#testing)
- [Gas Metering](#gas-metering)
- [Deployment](#deployment)
Expand Down Expand Up @@ -45,15 +44,15 @@ This section outlines the branching strategy of this repo.

### Main

The main branch is supposed to reflect the deployed state on all networks. Any pull requests into this branch MUST come from the staging branch. The main branch is protected and requires a separate code review by the security team. Whenever the main branch is updated, a new release is created with the latest version. For more information on versioning, check [here](#versioning).
The main branch is supposed to reflect the deployed state on all networks. Any pull requests into this branch MUST come from the staging branch.

### Staging

The staging branch reflects new code complete deployments or upgrades containing fixes and/or features. Any pull requests into this branch MUST come from the dev branch. The staging branch is used for security audits and deployments. Once the deployment is complete and deployment log files are generated, the branch can be merged into main. For more information on the deployment and log file generation check [here](#deployment--versioning).
The staging branch reflects new code complete deployments or upgrades containing fixes and/or features. Any pull requests into this branch MUST come from the dev branch. The staging branch is used for security audits and deployments. Once the deployment is complete and verified as well as deployment log files are generated, the branch can be merged into main. For more information on the deployment and log file generation check [here](#deployment).

### Dev

This is the active development branch. All pull requests into this branch MUST come from fix or feature branches. Upon code completion this branch is merged into staging for auditing and deployment.
This is the active development branch. All pull requests into this branch MUST come from fix or feature branches. Upon code completion this branch is merged into staging for auditing and deployment. PRs into this branch should squash all commits into a single commit.

### Feature

Expand Down Expand Up @@ -114,12 +113,6 @@ Every contract MUST implement their corresponding interface that includes all ex

Interfaces should be the entrypoint for all contracts. When exploring the a contract within the repository, the interface MUST contain all relevant information to understand the functionality of the contract in the form of NatSpec comments. This includes all externally callable functions, errors and events. The NatSpec documentation MUST be added to the functions, errors and events within the interface. This allows a reader to understand the functionality of a function before moving on to the implementation. The implementing functions MUST point to the NatSpec documentation in the interface using `@inheritdoc`. Internal and private functions shouldn't have NatSpec documentation except for `@dev` comments, whenever more context is needed. Additional comments within a function should only be used to give more context to more complex operations, otherwise the code should be kept readable and self-explanatory.

## Versioning

This repo utilizes [semantic versioning](https://semver.org/) for smart contracts. An `IVersioned` interface is included in the [interfaces directory](src/interface/IVersioned.sol) exposing a unified versioning interface for all contracts. This version MUST be included in all contracts, whether they are upgradeable or not, to be able to easily match deployed versions. For example, in the case of a non-upgradeable contract one version could be deployed to a network and later a new version might be deployed to another network. The exposed `version()` function is also used by the [Deployment Log Generator](https://github.com/0xPolygon/forge-chronicles#readme) to extract information about the version.

Whenever contracts are modified, only the version of the changed contracts should be updated. Unmodified contracts should remain on the version of their last change.

## Testing

The following testing practices should be followed when writing unit tests for new code. All functions, lines and branches should be tested to result in 100% testing coverage. Fuzz parameters and conditions whenever possible. Extremes should be tested in dedicated edge case and corner case tests. Invariants should be tested in dedicated invariant tests.
Expand All @@ -140,7 +133,7 @@ When adding new functionality, a new gas snapshot should be added, preferably us

## Deployment

This repo utilizes versioned deployments. Any changes to a contract should update the version of this specific contract. A script is provided that extracts deployment information from the `run-latest.json` file within the `broadcast` directory generated while the forge script runs. From this information a JSON and markdown file is generated containing various information about the deployment itself as well as past deployments.
After deployments are executed a script is provided that extracts deployment information from the `run-latest.json` file within the `broadcast` directory generated while the forge script runs. From this information a JSON and markdown file is generated using the [Forge Chronicles](https://github.com/0xPolygon/forge-chronicles) library containing various information about the deployment itself as well as past deployments.

### Deployment

Expand Down
2 changes: 0 additions & 2 deletions docs/autogen/src/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
## Template Repo (Foundry)

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![CI Status](../../actions/workflows/test.yaml/badge.svg)](../../actions)

This template repo is a quick and easy way to get started with a new Solidity project. It comes with a number of features that are useful for developing and deploying smart contracts. Such as:
Expand All @@ -14,7 +13,6 @@ This template repo is a quick and easy way to get started with a new Solidity pr
- [Deployment](#deployment)
- [Docs](#docs)
- [Contributing](#contributing)
- [License](#license)

## Setup

Expand Down
1 change: 0 additions & 1 deletion docs/autogen/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
# src
- [❱ interface](src/interface/README.md)
- [ICounter](src/interface/ICounter.sol/interface.ICounter.md)
- [IVersioned](src/interface/IVersioned.sol/interface.IVersioned.md)
- [Counter](src/Counter.sol/contract.Counter.md)
26 changes: 3 additions & 23 deletions docs/autogen/src/src/Counter.sol/contract.Counter.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Counter
[Git Source](https://github.com/gretzke/foundry-template/blob/952489c408f511dc764c05d3a2a21ded78da224f/src/Counter.sol)
[Git Source](https://github.com/Uniswap/foundry-template/blob/6ed2d53f10b4739f84426a12bef01482d7a2e669/src/Counter.sol)

**Inherits:**
[ICounter](/src/interface/ICounter.sol/interface.ICounter.md), Initializable
[ICounter](/src/interface/ICounter.sol/interface.ICounter.md)


## State Variables
Expand All @@ -18,14 +18,7 @@ uint256 public number;


```solidity
constructor();
```

### initialize


```solidity
function initialize(uint256 initialNumber) public initializer;
constructor(uint256 initialNumber);
```

### setNumber
Expand All @@ -52,16 +45,3 @@ Increments the number by 1
function increment() public;
```

### version


```solidity
function version() external pure returns (string memory);
```
**Returns**

|Name|Type|Description|
|----|----|-----------|
|`<none>`|`string`|The version of the contract|


Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# ICounter
[Git Source](https://github.com/gretzke/foundry-template/blob/952489c408f511dc764c05d3a2a21ded78da224f/src/interface/ICounter.sol)

**Inherits:**
[IVersioned](/src/interface/IVersioned.sol/interface.IVersioned.md)
[Git Source](https://github.com/Uniswap/foundry-template/blob/6ed2d53f10b4739f84426a12bef01482d7a2e669/src/interface/ICounter.sol)


## Functions
Expand Down
1 change: 0 additions & 1 deletion docs/autogen/src/src/interface/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

# Contents
- [ICounter](ICounter.sol/interface.ICounter.md)
- [IVersioned](IVersioned.sol/interface.IVersioned.md)
8 changes: 4 additions & 4 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
pragma solidity 0.8.23;

import "forge-std/Script.sol";
import "script/deployers/CounterDeployer.s.sol";

contract Deploy is Script, CounterDeployer {
import {Counter} from "src/Counter.sol";

contract Deploy is Script {
using stdJson for string;

function run() public {
address proxyAdmin = address(1);
uint256 initialNumber = 5;
deployCounterTransparent(proxyAdmin, initialNumber);
new Counter(initialNumber);
}
}
43 changes: 0 additions & 43 deletions script/deployers/CounterDeployer.s.sol

This file was deleted.

16 changes: 3 additions & 13 deletions src/Counter.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.23;

import {ICounter, IVersioned} from "./interface/ICounter.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {ICounter} from "./interface/ICounter.sol";

contract Counter is ICounter, Initializable {
contract Counter is ICounter {
uint256 public number;

constructor() {
_disableInitializers();
}

function initialize(uint256 initialNumber) public initializer {
constructor(uint256 initialNumber) {
number = initialNumber;
}

Expand All @@ -24,9 +19,4 @@ contract Counter is ICounter, Initializable {
function increment() public {
number++;
}

/// @inheritdoc IVersioned
function version() external pure returns (string memory) {
return "1.0.0";
}
}
4 changes: 1 addition & 3 deletions src/interface/ICounter.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.23;

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

interface ICounter is IVersioned {
interface ICounter {
/// @return The current number
function number() external view returns (uint256);

Expand Down
7 changes: 0 additions & 7 deletions src/interface/IVersioned.sol

This file was deleted.

35 changes: 5 additions & 30 deletions test/Counter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,22 @@ pragma solidity 0.8.23;
import "forge-std/Test.sol";
import "test/util/TestHelpers.sol";

import "script/deployers/CounterDeployer.s.sol";
import {Counter} from "src/Counter.sol";

abstract contract BeforeScript is Test, TestHelpers, CounterDeployer {
function setUp() public virtual {
counter = Counter(deployCounterImplementation());
}
}

contract CounterTest_Zero is BeforeScript {
function test_InitialState() public {
assertEq(counter.number(), 0);
}

function test_RevertsOnInitialization(uint256 number) public {
vm.expectRevert(Initializable.InvalidInitialization.selector);
counter.initialize(number);
}
}
abstract contract Deployed is Test, TestHelpers {
Counter counter;

abstract contract AfterScript is Test, TestHelpers, CounterDeployer {
function setUp() public virtual {
address proxyAdmin = makeAddr("alice");
uint256 initialNumber = 10;
deployCounterTransparent(proxyAdmin, initialNumber);
counter = new Counter(initialNumber);
}
}

contract CounterTest_Initialized is AfterScript {
contract CounterTest_Deployed is Deployed {
function test_IsInitialized() public {
assertEq(counter.number(), 10);
}

function test_RevertsIf_InitializedAgain() public {
vm.expectRevert(Initializable.InvalidInitialization.selector);
counter.initialize(1);
}

function test_IncrementsNumber() public {
counter.increment();
assertEq(counter.number(), 11);
Expand All @@ -50,8 +29,4 @@ contract CounterTest_Initialized is AfterScript {
counter.setNumber(x);
assertEq(counter.number(), x);
}

function test_ReturnsVersion() public {
assertEq(counter.version(), "1.0.0");
}
}

0 comments on commit 58d15c2

Please sign in to comment.