Skip to content

Commit

Permalink
vochain: remove treasurer logic
Browse files Browse the repository at this point in the history
  • Loading branch information
p4u committed Oct 23, 2023
1 parent d6a9665 commit 2c357eb
Show file tree
Hide file tree
Showing 26 changed files with 33 additions and 806 deletions.
35 changes: 0 additions & 35 deletions api/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ func (a *API) enableAccountHandlers() error {
); err != nil {
return err
}
if err := a.endpoint.RegisterMethod(
"/accounts/treasurer",
"GET",
apirest.MethodAccessTypePublic,
a.treasurerHandler,
); err != nil {
return err
}
if err := a.endpoint.RegisterMethod(
"/accounts/{organizationID}/elections/count",
"GET",
Expand Down Expand Up @@ -243,33 +235,6 @@ func (a *API) accountSetHandler(msg *apirest.APIdata, ctx *httprouter.HTTPContex
return ctx.Send(data, apirest.HTTPstatusOK)
}

// treasurerHandler
//
// @Summary Get treasurer address
// @Description Get treasurer address. The treasurer is a new authority entity identified by its Ethereum address and is the only one that can Mint new tokens.
// @Tags Accounts
// @Accept json
// @Produce json
// @Success 200 {object} object{address=string}
// @Router /accounts/treasurer [get]
func (a *API) treasurerHandler(_ *apirest.APIdata, ctx *httprouter.HTTPContext) error {
acc, err := a.vocapp.State.Treasurer(true)
if err != nil {
return err
}
if acc == nil {
return ErrTreasurerNotFound
}
data, err := json.Marshal(struct {
Address types.HexBytes `json:"address"`
}{Address: acc.GetAddress()})

if err != nil {
return err
}
return ctx.Send(data, apirest.HTTPstatusOK)
}

// electionListHandler
//
// @Summary List organization elections
Expand Down
1 change: 0 additions & 1 deletion api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var (
ErrDstAccountUnknown = apirest.APIerror{Code: 4002, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("destination account is unknown")}
ErrAccountNotFound = apirest.APIerror{Code: 4003, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("account not found")}
ErrAccountAlreadyExists = apirest.APIerror{Code: 4004, HTTPstatus: apirest.HTTPstatusBadRequest, Err: fmt.Errorf("account already exists")}
ErrTreasurerNotFound = apirest.APIerror{Code: 4005, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("treasurer account not found")}
ErrOrgNotFound = apirest.APIerror{Code: 4006, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("organization not found")}
ErrTransactionNotFound = apirest.APIerror{Code: 4007, HTTPstatus: apirest.HTTPstatusNoContent, Err: fmt.Errorf("transaction not found")}
ErrBlockNotFound = apirest.APIerror{Code: 4008, HTTPstatus: apirest.HTTPstatusNotFound, Err: fmt.Errorf("block not found")}
Expand Down
17 changes: 0 additions & 17 deletions apiclient/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,6 @@ var (
ErrAccountNotConfigured = fmt.Errorf("account not configured")
)

// Treasurer returns the treasurer address.
func (c *HTTPclient) Treasurer() (*api.Account, error) {
resp, code, err := c.Request(HTTPGET, nil, "accounts", "treasurer")
if err != nil {
return nil, err
}
if code != apirest.HTTPstatusOK {
return nil, fmt.Errorf("%s: %d (%s)", errCodeNot200, code, resp)
}
acc := &api.Account{}
err = json.Unmarshal(resp, acc)
if err != nil {
return nil, err
}
return acc, nil
}

// Account returns the information about a Vocdoni account. If address is empty, it returns the information
// about the account associated with the client.
func (c *HTTPclient) Account(address string) (*api.Account, error) {
Expand Down
6 changes: 3 additions & 3 deletions apiclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (

const (
// HTTPGET is the method string used for calling Request()
HTTPGET = "GET"
HTTPGET = http.MethodGet
// HTTPPOST is the method string used for calling Request()
HTTPPOST = "POST"
HTTPPOST = http.MethodPost
// HTTPDELETE is the method string used for calling
HTTPDELETE = "DELETE"
HTTPDELETE = http.MethodDelete

errCodeNot200 = "API error"

Expand Down
23 changes: 0 additions & 23 deletions cmd/end2endtest/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"sync"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/google/go-cmp/cmp"
apipkg "go.vocdoni.io/dvote/api"
"go.vocdoni.io/dvote/apiclient"
Expand Down Expand Up @@ -62,11 +61,6 @@ func (t *E2ETokenTxs) Setup(api *apiclient.HTTPclient, config *config) error {
return err
}

// check transaction cost
if err := testGetTxCost(t.api); err != nil {
return fmt.Errorf("error in testGetTxCost: %w", err)
}

// check create and set account
if err := testCreateAndSetAccount(t.api, t.aliceFP, t.alice, t.bob); err != nil {
return fmt.Errorf("error in testCreateAndSetAccount: %w", err)
Expand All @@ -89,23 +83,6 @@ func (t *E2ETokenTxs) Run() error {
return nil
}

func testGetTxCost(api *apiclient.HTTPclient) error {
// get treasurer nonce
treasurer, err := api.Treasurer()
if err != nil {
return err
}
log.Infof("treasurer is %s", common.BytesToAddress(treasurer.Address))

// get current tx cost
txCost, err := api.TransactionCost(models.TxType_SET_ACCOUNT_INFO_URI)
if err != nil {
return err
}
log.Infow("fetched tx cost", "type", models.TxType_SET_ACCOUNT_INFO_URI.String(), "cost", txCost)
return nil
}

func testCreateAndSetAccount(api *apiclient.HTTPclient, fp *models.FaucetPackage, alice, bob *ethereum.SignKeys) error {
// create account with faucet package
aliceAcc, err := ensureAccountExists(api.Clone(hex.EncodeToString(alice.PrivateKey())), fp)
Expand Down
22 changes: 10 additions & 12 deletions cmd/end2endtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,16 @@ func opNames() (names []string) {
}

type config struct {
host string
logLevel string
operation string
accountPrivKeys []string
accountKeys []*ethereum.SignKeys
treasurerPrivKey string
nvotes int
parallelCount int
faucet string
faucetAuthToken string
timeout time.Duration
host string
logLevel string
operation string
accountPrivKeys []string
accountKeys []*ethereum.SignKeys
nvotes int
parallelCount int
faucet string
faucetAuthToken string
timeout time.Duration
}

func main() {
Expand All @@ -83,7 +82,6 @@ func main() {
fmt.Sprintf("set operation mode: %v", opNames()))
flag.StringSliceVarP(&c.accountPrivKeys, "accountPrivKey", "k", []string{},
"account private key (optional)")
flag.StringVar(&c.treasurerPrivKey, "treasurerPrivKey", "", "treasurer private key")
flag.IntVar(&c.nvotes, "votes", 10, "number of votes to cast")
flag.IntVar(&c.parallelCount, "parallel", 4, "number of parallel requests")
flag.StringVar(&c.faucet, "faucet", "dev",
Expand Down
32 changes: 8 additions & 24 deletions cmd/voconed/voconed.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import (

// VoconeConfig contains the basic configuration for the voconed
type VoconeConfig struct {
logLevel, dir, keymanager, path, treasurer, chainID string
port, blockSeconds, blockSize int
txCosts uint64
disableIpfs bool
fundedAccounts []string
enableFaucetWithAmount uint64
ipfsConnectKey string
ipfsConnectPeers []string
logLevel, dir, keymanager, path, chainID string
port, blockSeconds, blockSize int
txCosts uint64
disableIpfs bool
fundedAccounts []string
enableFaucetWithAmount uint64
ipfsConnectKey string
ipfsConnectPeers []string
}

func main() {
Expand All @@ -49,7 +49,6 @@ func main() {
}
flag.StringVar(&config.dir, "dir", filepath.Join(home, ".voconed"), "storage data directory")
flag.StringVar(&config.keymanager, "keymanager", "", "key manager private hexadecimal key")
flag.StringVar(&config.treasurer, "treasurer", "", "treasurer address")
flag.StringVar(&config.logLevel, "logLevel", "info", "log level (info, debug, warn, error)")
flag.StringVar(&config.chainID, "chainID", "vocone", "defines the chainID")
flag.IntVar(&config.port, "port", 9090, "network port for the HTTP API")
Expand Down Expand Up @@ -196,21 +195,6 @@ func main() {
vc.App.SetChainID(config.chainID)
log.Infof("using chainID: %s", config.chainID)

// set treasurer address if provided
if len(config.treasurer) > 0 {
log.Infof("setting treasurer %s", config.treasurer)
if err := vc.SetTreasurer(common.HexToAddress(config.treasurer)); err != nil {
log.Fatal(err)
}
}
// set transaction costs
if *setTxCosts {
log.Infof("setting tx costs to %d", config.txCosts)
if err := vc.SetBulkTxCosts(config.txCosts, true); err != nil {
log.Fatal(err)
}
}

// set election price calculator
if err := vc.SetElectionPrice(); err != nil {
log.Fatal(err)
Expand Down
1 change: 0 additions & 1 deletion dockerfiles/testsuite/env.treasurerkey

This file was deleted.

1 change: 0 additions & 1 deletion dockerfiles/testsuite/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"balance":1000000000000
}
],
"treasurer": "0xfe10DAB06D636647f4E40dFd56599da9eF66Db1c",
"tx_cost": {
"Tx_SetProcessStatus": 1,
"Tx_SetProcessCensus": 1,
Expand Down
4 changes: 1 addition & 3 deletions dockerfiles/testsuite/start_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ ACCOUNT_KEYS=${ACCOUNT_KEYS:-$DEFAULT_ACCOUNT_KEYS}
GWHOST="http://gateway0:9090/dvote"
APIHOST="http://gateway0:9090/v2"
FAUCET="$APIHOST/faucet/dev/"
. env.treasurerkey # contains var VOCDONI_SIGNINGKEY, import into current env
TREASURER_KEY="$VOCDONI_SIGNINGKEY"
[ -n "$TESTSUITE_TREASURER_KEY" ] && TREASURER_KEY="$TESTSUITE_TREASURER_KEY"
TEST_PREFIX="testsuite_test"
RANDOMID="${RANDOM}${RANDOM}"

Expand Down Expand Up @@ -158,6 +155,7 @@ e2etest_ballotelection() {

log "### Starting test suite ###"
$COMPOSE_CMD build
$COMPOSE_CMD build test
$COMPOSE_CMD up -d seed # start the seed first so the nodes can properly bootstrap
sleep 10
$COMPOSE_CMD up -d
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ require (
github.com/vocdoni/storage-proofs-eth-go v0.1.6
go.mongodb.org/mongo-driver v1.12.1
go.uber.org/atomic v1.11.0
go.vocdoni.io/proto v1.15.4-0.20231017174559-1d9ea54cd9ad
go.vocdoni.io/proto v1.15.4-0.20231023165811-02adcc48142a
golang.org/x/crypto v0.14.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/net v0.16.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1646,8 +1646,8 @@ go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI=
go.uber.org/zap v1.25.0 h1:4Hvk6GtkucQ790dqmj7l1eEnRdKm3k3ZUrUMS2d5+5c=
go.uber.org/zap v1.25.0/go.mod h1:JIAUzQIH94IC4fOJQm7gMmBJP5k7wQfdcnYdPoEXJYk=
go.vocdoni.io/proto v1.15.4-0.20231017174559-1d9ea54cd9ad h1:v+ixFtzq/7nwa/y7lY/LiFcVOPjK7aF9EpyX6RWCS2M=
go.vocdoni.io/proto v1.15.4-0.20231017174559-1d9ea54cd9ad/go.mod h1:oi/WtiBFJ6QwNDv2aUQYwOnUKzYuS/fBqXF8xDNwcGo=
go.vocdoni.io/proto v1.15.4-0.20231023165811-02adcc48142a h1:88Dg0JNhT9004TuZoHIX44zkaHkInKgBgBaA0S12cYY=
go.vocdoni.io/proto v1.15.4-0.20231023165811-02adcc48142a/go.mod h1:oi/WtiBFJ6QwNDv2aUQYwOnUKzYuS/fBqXF8xDNwcGo=
go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE=
go4.org v0.0.0-20200411211856-f5505b9728dd/go.mod h1:CIiUVy99QCPfoE13bO4EZaz5GZMZXMSBGhxRdsvzbkg=
go4.org v0.0.0-20230225012048-214862532bf5 h1:nifaUDeh+rPaBCMPMQHZmvJf+QdpLFnuQPwx+LxVmtc=
Expand Down
32 changes: 0 additions & 32 deletions test/testcommon/vochain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"go.vocdoni.io/dvote/db"
"go.vocdoni.io/dvote/test/testcommon/testutil"
"go.vocdoni.io/dvote/util"
"go.vocdoni.io/dvote/vochain"
"go.vocdoni.io/dvote/vochain/indexer"
"go.vocdoni.io/dvote/vochain/state"
Expand Down Expand Up @@ -49,37 +48,6 @@ var (
Process: ProcessHardcoded,
VotesRoot: make([]byte, 32),
}

// privKey e0aa6db5a833531da4d259fb5df210bae481b276dc4c2ab6ab9771569375aed5 for address 06d0d2c41f4560f8ffea1285f44ce0ffa2e19ef0
HardcodedNewProcessTx = &models.NewProcessTx{
Txtype: models.TxType_NEW_PROCESS,
Process: ProcessHardcoded,
Nonce: 0,
}

HardcodedNewVoteTx = &models.VoteEnvelope{
Nonce: util.RandomBytes(32),
Nullifier: testutil.Hex2byte(nil, "5592f1c18e2a15953f355c34b247d751da307338c994000b9a65db1dc14cc6c0"),
ProcessId: testutil.Hex2byte(nil, "e9d5e8d791f51179e218c606f83f5967ab272292a6dbda887853d81f7a1d5105"),
Proof: &models.Proof{Payload: &models.Proof_Graviton{Graviton: &models.ProofGraviton{
Siblings: testutil.Hex2byte(nil, "00030000000000000000000000000000000000000000000000000000000000070ab34471caaefc9bb249cb178335f367988c159f3907530ef7daa1e1bf0c9c7a218f981be7c0c46ffa345d291abb36a17c22722814fb0110240b8640fd1484a6268dc2f0fc2152bf83c06566fbf155f38b8293033d4779a63bba6c7157fd10c8"),
}}},
VotePackage: testutil.B642byte(nil, "eyJ0eXBlIjoicG9sbC12b3RlIiwibm9uY2UiOiI1NTkyZjFjMThlMmExNTk1M2YzNTVjMzRiMjQ3ZDc1MWRhMzA3MzM4Yzk5NDAwMGI5YTY1ZGIxZGMxNGNjNmMwIiwidm90ZXMiOlsxLDIsMV19"),
}

power = uint64(10)
HardcodedAdminTxAddValidator = &models.AdminTx{
Txtype: models.TxType_ADD_VALIDATOR,
Address: testutil.Hex2byte(nil, "5DC922017285EC24415F3E7ECD045665EADA8B5A"),
Nonce: 0,
Power: &power,
}

HardcodedAdminTxRemoveValidator = &models.AdminTx{
Txtype: models.TxType_REMOVE_VALIDATOR,
Address: testutil.Hex2byte(nil, "5DC922017285EC24415F3E7ECD045665EADA8B5A"),
Nonce: 0,
}
)

func NewVochainState(tb testing.TB) *state.State {
Expand Down
Loading

0 comments on commit 2c357eb

Please sign in to comment.