Skip to content

Commit

Permalink
Migrate governance-contracts (#89)
Browse files Browse the repository at this point in the history
* migrate : governance-contract

* panic: core.GenerateChain

* fix: test panic

* fix : FakeMode, escape futureBlock

* fix : panic bad block

* refact : mv wemix_backends -> wemix package

* refact : remove common/bn

* refact : GovContracts

* fix : remove unused

* fix : rename confusing variable

* fix : unhandled error

* fix : code style

* refact: migrate openzeppelin contract:v4.6.0, contracts-upgrade:v4.7.0

* feat : update governancedeploy use wemix/bind

* fix : remove unused

* fix : default init envstorage values

* fix : gwemix.sh

* fix : compare fixed bytes

* fix : compare fixed bytes

* fix : typo

* fix : Flag type

* feat : update genesisConfig

* fix : remove unused code

* fix : deploy log

* feat : wemix simulated OptionFn

* feat : install solc

* fix : typo

* fix : typo

* fix : error verifyBlockSig

* fix : remove unused file

* fix : gwemix.sh

* fix: go.mod

* refact : using bind structs

* docs : gwemix.sh comment

* refact : submodule openzeppelin

* feat : using NCPExit

* wip : dev-ci

* fix : unuse generic

* fix : TestWemixBackends$

* feat : using generic, remove lint_test go@1.17

* fix: go:generate

* fix : clean code

* fix : remove comment

* fix : clean code

* feat : (governance abigen) compare data before writing to the file

* refact : using compiledTy

* feat : include sigs wemix/bind contracts

* refacet : move compiled, remove simulated-backend

* fix : clean code

* fix : clean code

* fix : detailed tick processing

* feat : [init-gov] add option password

* fix : gwemix.sh init-gov params

* fix : [init-gov] add option password

* refact : use const

* fix : use constant

* fix : loadGenesisConfig

* fix : check bootnodeExists

---------

Co-authored-by: egonspace <egonspace@gmail.com>
  • Loading branch information
felix-shin-wt and egonspace authored Jul 3, 2024
1 parent 0651567 commit 71325e9
Show file tree
Hide file tree
Showing 71 changed files with 33,426 additions and 2,144 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/dev-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
strategy:
fail-fast: false
matrix:
version: [1.17, 1.18, 1.19]
version: [1.18, 1.19]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
Expand All @@ -38,7 +38,7 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.version }}

- name: Check Lint
run: make lint

Expand All @@ -49,6 +49,9 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up Wemix Submodules
run: git submodule update --init wemix/

- name: Set up Go
uses: actions/setup-go@v3
with:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/gwemix-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
strategy:
fail-fast: false
matrix:
version: [1.17, 1.18, 1.19]
version: [1.18, 1.19]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
Expand All @@ -49,6 +49,9 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up Wemix Submodules
run: git submodule update --init wemix/

- name: Set up Go
uses: actions/setup-go@v3
with:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/master-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
strategy:
fail-fast: false
matrix:
version: [1.17, 1.18, 1.19]
version: [1.18, 1.19]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
Expand All @@ -49,6 +49,9 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up Wemix Submodules
run: git submodule update --init wemix/

- name: Set up Go
uses: actions/setup-go@v3
with:
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@
[submodule "etcd"]
path = etcd
url = https://github.com/metadium/etcd
[submodule "wemix/governance-contract/contracts/openzeppelin/contracts-upgradeable"]
path = wemix/governance-contract/contracts/openzeppelin/contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "wemix/governance-contract/contracts/openzeppelin/contracts"]
path = wemix/governance-contract/contracts/openzeppelin/contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
79 changes: 5 additions & 74 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ endif

gwemix.tar.gz: gwemix logrot
@[ -d build/conf ] || mkdir -p build/conf
@cp -p wemix/scripts/gwemix.sh wemix/scripts/solc.sh build/bin/
@cp -p wemix/scripts/gwemix.sh build/bin/
@cp -p wemix/scripts/config.json.example \
wemix/scripts/genesis-template.json \
wemix/contracts/WemixGovernance.js \
wemix/scripts/deploy-governance.js \
build/conf/
@(cd build; tar cfz gwemix.tar.gz bin conf)
@echo "Done building build/gwemix.tar.gz"

gwemix: rocksdb wemix/governance_abi.go
gwemix: rocksdb
ifeq ($(USE_ROCKSDB), NO)
$(GORUN) build/ci.go install $(ROCKSDB_TAG) ./cmd/gwemix
else
Expand Down Expand Up @@ -68,7 +66,7 @@ else
$(GORUN) build/ci.go install $(ROCKSDB_TAG) ./cmd/dbbench
endif

all: wemix/governance_abi.go
all:
$(GORUN) build/ci.go install

android:
Expand All @@ -89,12 +87,12 @@ test: all
test-short: all
$(GORUN) build/ci.go test -short

lint: wemix/governance_abi.go ## Run linters.
lint: ## Run linters.
$(GORUN) build/ci.go lint

clean:
env GO111MODULE=on go clean -cache
rm -fr build/_workspace/pkg/ $(GOBIN)/* build/conf wemix/admin_abi.go wemix/governance_abi.go
rm -fr build/_workspace/pkg/ $(GOBIN)/* build/conf
@ROCKSDB_DIR=$(ROCKSDB_DIR); \
if [ -e $${ROCKSDB_DIR}/Makefile ]; then \
cd $${ROCKSDB_DIR}; \
Expand Down Expand Up @@ -132,70 +130,3 @@ rocksdb:
@[ ! -e rocksdb/.git ] && git submodule update --init rocksdb; \
cd $(ROCKSDB_DIR) && PORTABLE=1 make -j8 static_lib;
endif

AWK_CODE=' \
BEGIN { print "package wemix"; bin = 0; name = ""; abi = ""; } \
/^{/ { bin = 1; abi = ""; name = ""; } \
/^}/ { bin = 0; abi = abi "}"; print "var " name "Abi = `" abi "`"; } \
{ \
if (bin == 1) { \
abi = abi $$0; \
if ($$1 == "\"contractName\":") { \
name = $$2; \
gsub(",|\"", "", name); \
} \
} \
}'

wemix/admin_abi.go: wemix/contracts/WemixAdmin-template.sol build/bin/solc
@PATH=${PATH}:build/bin wemix/scripts/solc.sh -f abi $< /tmp/junk.$$$$; \
cat /tmp/junk.$$$$ | awk $(AWK_CODE) > $@; \
rm -f /tmp/junk.$$$$;

AWK_CODE_2=' \
BEGIN { print "package wemix\n"; } \
/^var Registry_contract/ { \
sub("^var[^(]*\\(","",$$0); sub("\\);$$","",$$0); \
n = "Registry"; \
print "var " n "Abi = `{ \"contractName\": \"" n "\", \"abi\": " $$0 "}`"; \
} \
/^var StakingImp_contract/ { \
sub("^var[^(]*\\(","",$$0); sub("\\);$$","",$$0); \
n = "Staking"; \
print "var " n "Abi = `{ \"contractName\": \"" n "\", \"abi\": " $$0 "}`"; \
} \
/^var EnvStorageImp_contract/ { \
sub("^var[^(]*\\(","",$$0); sub("\\);$$","",$$0); \
n = "EnvStorageImp"; \
print "var " n "Abi = `{ \"contractName\": \"" n "\", \"abi\": " $$0 "}`"; \
} \
/^var GovImp_contract/ { \
sub("^var[^(]*\\(","",$$0); sub("\\);$$","",$$0); \
n = "Gov"; \
print "var " n "Abi = `{ \"contractName\": \"" n "\", \"abi\": " $$0 "}`"; \
}'

wemix/governance_abi.go: wemix/contracts/WemixGovernance.js
@cat $< | awk $(AWK_CODE_2) > $@

ifneq ($(shell uname), Linux)

build/bin/solc:
@test 1

else

SOLC_URL=https://github.com/ethereum/solidity/releases/download/v0.4.24/solc-static-linux
build/bin/solc:
@[ -d build/bin ] || mkdir -p build/bin; \
if [ ! -x build/bin/solc ]; then \
if which curl > /dev/null 2>&1; then \
curl -Ls -o build/bin/solc $(SOLC_URL); \
chmod +x build/bin/solc; \
elif which wget > /dev/null 2>&1; then \
wget -nv -o build/bin/solc $(SOLC_URL); \
chmod +x build/bin/solc; \
fi \
fi

endif
15 changes: 15 additions & 0 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
Expand Down Expand Up @@ -72,6 +73,20 @@ type SimulatedBackend struct {
config *params.ChainConfig
}

func NewSimulatedBackendWithEthereum(e *eth.Ethereum) *SimulatedBackend {
database := e.ChainDb()
blockchain := e.BlockChain()

backend := &SimulatedBackend{
database: database,
blockchain: blockchain,
config: blockchain.Config(),
events: filters.NewEventSystem(&filterBackend{database, blockchain}, false),
}
backend.rollback(blockchain.CurrentBlock())
return backend
}

// NewSimulatedBackendWithDatabase creates a new binding backend based on the given database
// and uses a simulated blockchain for testing purposes.
// A simulated backend always uses chainID 1337.
Expand Down
Loading

0 comments on commit 71325e9

Please sign in to comment.