Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ RUN make lint
RUN make test-poa
# Integration tests
RUN make test-integration
# Solidity tests
RUN make test-solidity
# Simulation tests
RUN make test-sim-benchmark-simulation
RUN make test-sim-full-app-fast
# Solidity tests
RUN make test-solidity

RUN touch /test.lock

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ test-sim-full-app-fast:
@cd ${CURDIR}/app && go test -mod=readonly -run TestFullAppSimulation \
-Enabled=true -NumBlocks=100 -BlockSize=200 -Commit=true -Period=5 -Params=${CURDIR}/tests/sim/params.json -v -timeout 24h

test-solidity:
@echo "Beginning solidity tests..."
./scripts/run-solidity-tests.sh
###############################################################################
### Coverage ###
###############################################################################
Expand Down
46 changes: 0 additions & 46 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/appmodule"
sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/cosmos/cosmos-sdk/x/auth/posthandler"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -54,7 +53,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/consensus"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
evmmempool "github.com/cosmos/evm/mempool"
"github.com/xrplevm/node/v9/x/poa"

"cosmossdk.io/log"
Expand Down Expand Up @@ -239,7 +237,6 @@ type App struct {
EvmKeeper *evmkeeper.Keeper
FeeMarketKeeper feemarketkeeper.Keeper
Erc20Keeper erc20keeper.Keeper
EVMMempool *evmmempool.ExperimentalEVMMempool

// exrp keepers
PoaKeeper poakeeper.Keeper
Expand Down Expand Up @@ -810,45 +807,6 @@ func New(

app.setAnteHandler(app.txConfig, cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted)))

if evmtypes.GetChainConfig() != nil {
mempoolConfig := &evmmempool.EVMMempoolConfig{
AnteHandler: app.GetAnteHandler(),
BlockGasLimit: 100_000_000,
}

evmMempool := evmmempool.NewExperimentalEVMMempool(
app.CreateQueryContext,
logger,
app.EvmKeeper,
app.FeeMarketKeeper,
app.txConfig,
app.clientCtx,
mempoolConfig,
)
app.EVMMempool = evmMempool

// Set the global mempool for RPC access
if err := evmmempool.SetGlobalEVMMempool(evmMempool); err != nil {
panic(err)
}

// Replace BaseApp mempool
app.SetMempool(evmMempool)

// Set custom CheckTx handler for nonce gap support
checkTxHandler := evmmempool.NewCheckTxHandler(evmMempool)
app.SetCheckTxHandler(checkTxHandler)

// Set custom PrepareProposal handler
abciProposalHandler := baseapp.NewDefaultProposalHandler(evmMempool, app)
abciProposalHandler.SetSignerExtractionAdapter(
evmmempool.NewEthSignerExtractionAdapter(
sdkmempool.NewDefaultSignerExtractionAdapter(),
),
)
app.SetPrepareProposal(abciProposalHandler.PrepareProposalHandler())
}

app.setPostHandler()
app.setupUpgradeHandlers()

Expand Down Expand Up @@ -1112,10 +1070,6 @@ func (app *App) GetStakingKeeperSDK() *stakingkeeper.Keeper {
return app.StakingKeeper
}

// func (app *App) GetMempool() sdkmempool.ExtMempool {
// return app.EVMMempool
//}

func (app *App) GetAnteHandler() sdk.AnteHandler {
return app.BaseApp.AnteHandler()
}
Expand Down
78 changes: 78 additions & 0 deletions contracts/precompiles/erc20/IERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);

/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);

/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);

/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);

/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);

/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);

/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);

/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
39 changes: 39 additions & 0 deletions contracts/precompiles/erc20/IERC20Burnable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./IERC20.sol";

/**
* @dev Extension of {ERC20} that allows token holders to destroy both their own
* tokens and those that they have an allowance for, in a way that can be
* recognized off-chain (via event analysis).
*/
interface IERC20Burnable is IERC20 {
/**
* @dev Destroys `amount` tokens from the caller.
*
* See {ERC20-_burn}.
*/
function burn(uint256 amount) external;

/**
* @dev Destroys `amount` tokens from `from`.
*
* See {ERC20-_burn} and {ERC20-allowance}.
*
*/
function burn(address from, uint256 amount) external;

/**
* @dev Destroys a `value` amount of tokens from `account`, deducting from
* the caller's allowance.
*
* See {ERC20-_burn} and {ERC20-allowance}.
*
* Requirements:
*
* - the caller must have allowance for ``accounts``'s tokens of at least
* `value`.
*/
function burnFrom(address account, uint256 value) external;
}
31 changes: 31 additions & 0 deletions contracts/precompiles/erc20/IERC20Metadata.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./IERC20Mintable.sol";
import "./IERC20Burnable.sol";
import "./IOwnable.sol";

/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20, IERC20Mintable, IERC20Burnable, IOwnable {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);

/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);

/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
33 changes: 33 additions & 0 deletions contracts/precompiles/erc20/IERC20MetadataAllowance.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.8.18;

/**
* @author Evmos Team
* @title ERC20 Metadata Allowance Interface
* @dev Interface for the optional metadata and allowance functions from the ERC20 standard.
*/
interface IERC20MetadataAllowance {
/** @dev Atomically increases the allowance granted to spender by the caller.
* This is an alternative to approve that can be used as a mitigation for problems described in
* IERC20.approve.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens added to the spender allowance.
* @return approved Boolean value to indicate if the approval was successful.
*/
function increaseAllowance(
address spender,
uint256 addedValue
) external returns (bool approved);

/** @dev Atomically decreases the allowance granted to spender by the caller.
* This is an alternative to approve that can be used as a mitigation for problems described in
* IERC20.approve.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount to be subtracted from the spender allowance.
* @return approved Boolean value to indicate if the approval was successful.
*/
function decreaseAllowance(
address spender,
uint256 subtractedValue
) external returns (bool approved);
}
9 changes: 9 additions & 0 deletions contracts/precompiles/erc20/IERC20Mintable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./IERC20.sol";

interface IERC20Mintable is IERC20 {

function mint(address account, uint256 amount) external returns (bool);
}
42 changes: 42 additions & 0 deletions contracts/precompiles/erc20/IOwnable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
interface IOwnable {
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);

/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);

event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

/**
* @dev Returns the address of the current owner.
*/
function owner() external view returns (address);


/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) external;
}
26 changes: 26 additions & 0 deletions scripts/run-solidity-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

export GOPATH="$HOME"/go
export PATH="$PATH":"$GOPATH"/bin

# remove existing data
rm -rf "$HOME"/.tmp-exrpd-solidity-tests

# used to exit on first error (any non-zero exit code)
set -e

# build evmd binary
make install

cd tests/solidity || exit

if command -v yarn &>/dev/null; then
yarn install
else
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install yarn
yarn install
fi

yarn test --network cosmos "$@"
1 change: 1 addition & 0 deletions tests/solidity/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sol linguist-language=Solidity
10 changes: 10 additions & 0 deletions tests/solidity/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# dependencies
node_modules/
cache/
artifacts/
# don't track the contracts on evmos directory because these are copied from the precompiles pkg of this repo
**/precompiles/contracts/evmos/*

# ignore package-lock files (only use yarn.lock)
package-lock.json
!yarn.lock
Loading