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
1,296 changes: 1,296 additions & 0 deletions app/app_parallel_test.go

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package app

import (
"time"

"github.com/spf13/viper"

"github.com/okx/okbchain/libs/cosmos-sdk/codec"
sdk "github.com/okx/okbchain/libs/cosmos-sdk/types"
authtypes "github.com/okx/okbchain/libs/cosmos-sdk/x/auth"
authexported "github.com/okx/okbchain/libs/cosmos-sdk/x/auth/exported"
abci "github.com/okx/okbchain/libs/tendermint/abci/types"
abcitypes "github.com/okx/okbchain/libs/tendermint/abci/types"
"github.com/okx/okbchain/libs/tendermint/libs/log"
"github.com/okx/okbchain/libs/tendermint/types"
dbm "github.com/okx/okbchain/libs/tm-db"
Expand Down Expand Up @@ -54,3 +59,41 @@ func Setup(isCheckTx bool, options ...Option) *OKBChainApp {

return app
}

func SetupWithGenesisAccounts(isCheckTx bool, genAccs []authexported.GenesisAccount, options ...Option) *OKBChainApp {
viper.Set(sdk.FlagDBBackend, string(dbm.MemDBBackend))
types.DBBackend = string(dbm.MemDBBackend)
db := dbm.NewMemDB()
app := NewOKBChainApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, 0)

if !isCheckTx {
setupOption := &SetupOption{chainId: ""}
for _, opt := range options {
opt(setupOption)
}
// init chain must be called to stop deliverState from being nil
genesisState := NewDefaultGenesisState()
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.Codec().MustMarshalJSON(authGenesis)
stateBytes, err := codec.MarshalJSONIndent(app.Codec(), genesisState)
if err != nil {
panic(err)
}

// Initialize the chain
testTime, _ := time.Parse("2006-01-02 15:04:05", "2017-04-11 13:33:37")
app.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
AppStateBytes: stateBytes,
ChainId: setupOption.chainId,
Time: testTime,
},
)

app.Commit(abcitypes.RequestCommit{})
app.BeginBlock(abci.RequestBeginBlock{Header: abcitypes.Header{Height: app.LastBlockHeight() + 1}})
}

return app
}
Binary file added app/testdata/cw20.wasm
Binary file not shown.
40 changes: 40 additions & 0 deletions app/testdata/freecall.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.18;
// pragma solidity >=0.7.0 <0.9.0;


contract FreeCall {
address public constant moduleAddress =
address(0x1033796B018B2bf0Fc9CB88c0793b2F275eDB624);

event __OKCCallToWasm(string wasmAddr, uint256 value, string data);

function callByWasm(string memory callerWasmAddr,string memory data) public payable returns (string memory response) {
string memory temp1 = strConcat("callByWasm return: ",callerWasmAddr);
string memory temp2 = strConcat(temp1," ---data: ");
string memory temp3 = strConcat(temp2,data);
return temp3;
}


function callToWasm(string memory wasmAddr, uint256 value, string memory data) public returns (bool success){
emit __OKCCallToWasm(wasmAddr,value,data);
return true;
}


function strConcat(string memory _a, string memory _b) internal returns (string memory){
bytes memory _ba = bytes(_a);
bytes memory _bb = bytes(_b);
string memory ret = new string(_ba.length + _bb.length);
bytes memory bret = bytes(ret);
uint k = 0;
for (uint i = 0; i < _ba.length; i++) {
bret[k++] = _ba[i];
}
for (uint i = 0; i < _bb.length; i++) {
bret[k++] = _bb[i];
}
return string(ret);
}
}
Binary file added app/testdata/freecall.wasm
Binary file not shown.
73 changes: 73 additions & 0 deletions app/testdata/precompile.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract ContractA {

address precomplieContarct = 0x0000000000000000000000000000000000000100;
uint256 public number;
event pushLog(string data);

function callWasm(string memory wasmAddr, string memory msgData,bool requireASuccess) public payable returns (bytes memory response){
number = number + 1;
(bool success, bytes memory data) = precomplieContarct.call{value: msg.value} (
abi.encodeWithSignature("callToWasm(string,string)", wasmAddr,msgData)
);
if (requireASuccess) {
require(success);
string memory res = abi.decode(data,(string));
emit pushLog(res);
}
number = number + 1;
return data;
}

function queryWasm(string memory msgData,bool requireASuccess) public payable returns (bytes memory response){
number = number + 1;
(bool success, bytes memory data) = precomplieContarct.call{value: msg.value} (
abi.encodeWithSignature("queryToWasm(string)",msgData)
);
if (requireASuccess) {
require(success);
string memory res = abi.decode(data,(string));
emit pushLog(res);
}
number = number + 1;
return data;
}

function callToWasm(string memory wasmAddr, string memory data) public payable returns (string memory response) {
return "";
}

function queryToWasm(string memory data) public view returns (string memory response) {
return "";
}
}

contract ContractB {
uint256 public number;

function callWasm(address contractA ,string memory wasmAddr, string memory msgData, bool requireASuccess,bool requireBSuccess) public payable returns (bytes memory response){
number = number + 1;
(bool success, bytes memory data) = contractA.call{value: msg.value} (
abi.encodeWithSignature("callWasm(string,string,bool)", wasmAddr,msgData,requireASuccess)
);
number = number + 1;
if (requireBSuccess) {
require(success);
}
return data;
}

function queryWasm(address contractA , string memory msgData, bool requireASuccess,bool requireBSuccess) public payable returns (bytes memory response){
number = number + 1;
(bool success, bytes memory data) = contractA.call{value: msg.value} (
abi.encodeWithSignature("queryWasm(string,bool)",msgData,requireASuccess)
);
number = number + 1;
if (requireBSuccess) {
require(success);
}
return data;
}
}
Binary file added app/testdata/precompile.wasm
Binary file not shown.
Loading