From 3017ed9919430b01b7535e0adff59e5aae985c8c Mon Sep 17 00:00:00 2001 From: MiniFrenchBread <103425574+MiniFrenchBread@users.noreply.github.com> Date: Tue, 13 Aug 2024 14:43:15 +0800 Subject: [PATCH] test: unit test --- precompiles/dasigners/IDASigners.abi | 40 ------- precompiles/dasigners/contract.go | 136 +---------------------- precompiles/dasigners/dasigners_test.go | 19 ++++ precompiles/dasigners/types.go | 2 +- x/dasigners/v1/keeper/msg_server_test.go | 71 ++++++++++++ x/dasigners/v1/testutil/suite.go | 3 + 6 files changed, 95 insertions(+), 176 deletions(-) create mode 100644 x/dasigners/v1/keeper/msg_server_test.go diff --git a/precompiles/dasigners/IDASigners.abi b/precompiles/dasigners/IDASigners.abi index 45b27da3..8919ca24 100644 --- a/precompiles/dasigners/IDASigners.abi +++ b/precompiles/dasigners/IDASigners.abi @@ -48,46 +48,6 @@ "name": "NewSigner", "type": "event" }, - { - "anonymous": false, - "inputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "tokensPerVote", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxVotesPerSigner", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxQuorums", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "epochBlocks", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "encodedSlices", - "type": "uint256" - } - ], - "indexed": false, - "internalType": "struct IDASigners.Params", - "name": "params", - "type": "tuple" - } - ], - "name": "ParamsUpdated", - "type": "event" - }, { "anonymous": false, "inputs": [ diff --git a/precompiles/dasigners/contract.go b/precompiles/dasigners/contract.go index 3d0fd48a..9b0e9dd2 100644 --- a/precompiles/dasigners/contract.go +++ b/precompiles/dasigners/contract.go @@ -30,7 +30,7 @@ var ( // DASignersMetaData contains all meta data concerning the DASigners contract. var DASignersMetaData = &bind.MetaData{ - ABI: "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"X\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"Y\",\"type\":\"uint256\"}],\"indexed\":false,\"internalType\":\"structBN254.G1Point\",\"name\":\"pkG1\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"uint256[2]\",\"name\":\"X\",\"type\":\"uint256[2]\"},{\"internalType\":\"uint256[2]\",\"name\":\"Y\",\"type\":\"uint256[2]\"}],\"indexed\":false,\"internalType\":\"structBN254.G2Point\",\"name\":\"pkG2\",\"type\":\"tuple\"}],\"name\":\"NewSigner\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"tokensPerVote\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"maxVotesPerSigner\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"maxQuorums\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"epochBlocks\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"encodedSlices\",\"type\":\"uint256\"}],\"indexed\":false,\"internalType\":\"structIDASigners.Params\",\"name\":\"params\",\"type\":\"tuple\"}],\"name\":\"ParamsUpdated\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"socket\",\"type\":\"string\"}],\"name\":\"SocketUpdated\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"epochNumber\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_epoch\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_quorumId\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"_quorumBitmap\",\"type\":\"bytes\"}],\"name\":\"getAggPkG1\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"X\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"Y\",\"type\":\"uint256\"}],\"internalType\":\"structBN254.G1Point\",\"name\":\"aggPkG1\",\"type\":\"tuple\"},{\"internalType\":\"uint256\",\"name\":\"total\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"hit\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_epoch\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_quorumId\",\"type\":\"uint256\"}],\"name\":\"getQuorum\",\"outputs\":[{\"internalType\":\"address[]\",\"name\":\"\",\"type\":\"address[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_epoch\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_quorumId\",\"type\":\"uint256\"},{\"internalType\":\"uint32\",\"name\":\"_rowIndex\",\"type\":\"uint32\"}],\"name\":\"getQuorumRow\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address[]\",\"name\":\"_account\",\"type\":\"address[]\"}],\"name\":\"getSigner\",\"outputs\":[{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"socket\",\"type\":\"string\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"X\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"Y\",\"type\":\"uint256\"}],\"internalType\":\"structBN254.G1Point\",\"name\":\"pkG1\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"uint256[2]\",\"name\":\"X\",\"type\":\"uint256[2]\"},{\"internalType\":\"uint256[2]\",\"name\":\"Y\",\"type\":\"uint256[2]\"}],\"internalType\":\"structBN254.G2Point\",\"name\":\"pkG2\",\"type\":\"tuple\"}],\"internalType\":\"structIDASigners.SignerDetail[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_account\",\"type\":\"address\"}],\"name\":\"isSigner\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"params\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"tokensPerVote\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"maxVotesPerSigner\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"maxQuorums\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"epochBlocks\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"encodedSlices\",\"type\":\"uint256\"}],\"internalType\":\"structIDASigners.Params\",\"name\":\"\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_epoch\",\"type\":\"uint256\"}],\"name\":\"quorumCount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"X\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"Y\",\"type\":\"uint256\"}],\"internalType\":\"structBN254.G1Point\",\"name\":\"_signature\",\"type\":\"tuple\"}],\"name\":\"registerNextEpoch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"socket\",\"type\":\"string\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"X\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"Y\",\"type\":\"uint256\"}],\"internalType\":\"structBN254.G1Point\",\"name\":\"pkG1\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"uint256[2]\",\"name\":\"X\",\"type\":\"uint256[2]\"},{\"internalType\":\"uint256[2]\",\"name\":\"Y\",\"type\":\"uint256[2]\"}],\"internalType\":\"structBN254.G2Point\",\"name\":\"pkG2\",\"type\":\"tuple\"}],\"internalType\":\"structIDASigners.SignerDetail\",\"name\":\"_signer\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"X\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"Y\",\"type\":\"uint256\"}],\"internalType\":\"structBN254.G1Point\",\"name\":\"_signature\",\"type\":\"tuple\"}],\"name\":\"registerSigner\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_account\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_epoch\",\"type\":\"uint256\"}],\"name\":\"registeredEpoch\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"_socket\",\"type\":\"string\"}],\"name\":\"updateSocket\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", + ABI: "[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"X\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"Y\",\"type\":\"uint256\"}],\"indexed\":false,\"internalType\":\"structBN254.G1Point\",\"name\":\"pkG1\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"uint256[2]\",\"name\":\"X\",\"type\":\"uint256[2]\"},{\"internalType\":\"uint256[2]\",\"name\":\"Y\",\"type\":\"uint256[2]\"}],\"indexed\":false,\"internalType\":\"structBN254.G2Point\",\"name\":\"pkG2\",\"type\":\"tuple\"}],\"name\":\"NewSigner\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"socket\",\"type\":\"string\"}],\"name\":\"SocketUpdated\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"epochNumber\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_epoch\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_quorumId\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"_quorumBitmap\",\"type\":\"bytes\"}],\"name\":\"getAggPkG1\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"X\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"Y\",\"type\":\"uint256\"}],\"internalType\":\"structBN254.G1Point\",\"name\":\"aggPkG1\",\"type\":\"tuple\"},{\"internalType\":\"uint256\",\"name\":\"total\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"hit\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_epoch\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_quorumId\",\"type\":\"uint256\"}],\"name\":\"getQuorum\",\"outputs\":[{\"internalType\":\"address[]\",\"name\":\"\",\"type\":\"address[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_epoch\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_quorumId\",\"type\":\"uint256\"},{\"internalType\":\"uint32\",\"name\":\"_rowIndex\",\"type\":\"uint32\"}],\"name\":\"getQuorumRow\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address[]\",\"name\":\"_account\",\"type\":\"address[]\"}],\"name\":\"getSigner\",\"outputs\":[{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"socket\",\"type\":\"string\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"X\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"Y\",\"type\":\"uint256\"}],\"internalType\":\"structBN254.G1Point\",\"name\":\"pkG1\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"uint256[2]\",\"name\":\"X\",\"type\":\"uint256[2]\"},{\"internalType\":\"uint256[2]\",\"name\":\"Y\",\"type\":\"uint256[2]\"}],\"internalType\":\"structBN254.G2Point\",\"name\":\"pkG2\",\"type\":\"tuple\"}],\"internalType\":\"structIDASigners.SignerDetail[]\",\"name\":\"\",\"type\":\"tuple[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_account\",\"type\":\"address\"}],\"name\":\"isSigner\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"params\",\"outputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"tokensPerVote\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"maxVotesPerSigner\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"maxQuorums\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"epochBlocks\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"encodedSlices\",\"type\":\"uint256\"}],\"internalType\":\"structIDASigners.Params\",\"name\":\"\",\"type\":\"tuple\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_epoch\",\"type\":\"uint256\"}],\"name\":\"quorumCount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"uint256\",\"name\":\"X\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"Y\",\"type\":\"uint256\"}],\"internalType\":\"structBN254.G1Point\",\"name\":\"_signature\",\"type\":\"tuple\"}],\"name\":\"registerNextEpoch\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"address\",\"name\":\"signer\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"socket\",\"type\":\"string\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"X\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"Y\",\"type\":\"uint256\"}],\"internalType\":\"structBN254.G1Point\",\"name\":\"pkG1\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"uint256[2]\",\"name\":\"X\",\"type\":\"uint256[2]\"},{\"internalType\":\"uint256[2]\",\"name\":\"Y\",\"type\":\"uint256[2]\"}],\"internalType\":\"structBN254.G2Point\",\"name\":\"pkG2\",\"type\":\"tuple\"}],\"internalType\":\"structIDASigners.SignerDetail\",\"name\":\"_signer\",\"type\":\"tuple\"},{\"components\":[{\"internalType\":\"uint256\",\"name\":\"X\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"Y\",\"type\":\"uint256\"}],\"internalType\":\"structBN254.G1Point\",\"name\":\"_signature\",\"type\":\"tuple\"}],\"name\":\"registerSigner\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_account\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_epoch\",\"type\":\"uint256\"}],\"name\":\"registeredEpoch\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"_socket\",\"type\":\"string\"}],\"name\":\"updateSocket\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", } // DASignersABI is the input ABI used to generate the binding from. @@ -686,140 +686,6 @@ func (_DASigners *DASignersFilterer) ParseNewSigner(log types.Log) (*DASignersNe return event, nil } -// DASignersParamsUpdatedIterator is returned from FilterParamsUpdated and is used to iterate over the raw logs and unpacked data for ParamsUpdated events raised by the DASigners contract. -type DASignersParamsUpdatedIterator struct { - Event *DASignersParamsUpdated // Event containing the contract specifics and raw log - - contract *bind.BoundContract // Generic contract to use for unpacking event data - event string // Event name to use for unpacking event data - - logs chan types.Log // Log channel receiving the found contract events - sub ethereum.Subscription // Subscription for errors, completion and termination - done bool // Whether the subscription completed delivering logs - fail error // Occurred error to stop iteration -} - -// Next advances the iterator to the subsequent event, returning whether there -// are any more events found. In case of a retrieval or parsing error, false is -// returned and Error() can be queried for the exact failure. -func (it *DASignersParamsUpdatedIterator) Next() bool { - // If the iterator failed, stop iterating - if it.fail != nil { - return false - } - // If the iterator completed, deliver directly whatever's available - if it.done { - select { - case log := <-it.logs: - it.Event = new(DASignersParamsUpdated) - if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { - it.fail = err - return false - } - it.Event.Raw = log - return true - - default: - return false - } - } - // Iterator still in progress, wait for either a data or an error event - select { - case log := <-it.logs: - it.Event = new(DASignersParamsUpdated) - if err := it.contract.UnpackLog(it.Event, it.event, log); err != nil { - it.fail = err - return false - } - it.Event.Raw = log - return true - - case err := <-it.sub.Err(): - it.done = true - it.fail = err - return it.Next() - } -} - -// Error returns any retrieval or parsing error occurred during filtering. -func (it *DASignersParamsUpdatedIterator) Error() error { - return it.fail -} - -// Close terminates the iteration process, releasing any pending underlying -// resources. -func (it *DASignersParamsUpdatedIterator) Close() error { - it.sub.Unsubscribe() - return nil -} - -// DASignersParamsUpdated represents a ParamsUpdated event raised by the DASigners contract. -type DASignersParamsUpdated struct { - Params IDASignersParams - Raw types.Log // Blockchain specific contextual infos -} - -// FilterParamsUpdated is a free log retrieval operation binding the contract event 0x68567739bd4f190697d9305da326fa28ef711443d08a390a05008a8afe822103. -// -// Solidity: event ParamsUpdated((uint256,uint256,uint256,uint256,uint256) params) -func (_DASigners *DASignersFilterer) FilterParamsUpdated(opts *bind.FilterOpts) (*DASignersParamsUpdatedIterator, error) { - - logs, sub, err := _DASigners.contract.FilterLogs(opts, "ParamsUpdated") - if err != nil { - return nil, err - } - return &DASignersParamsUpdatedIterator{contract: _DASigners.contract, event: "ParamsUpdated", logs: logs, sub: sub}, nil -} - -// WatchParamsUpdated is a free log subscription operation binding the contract event 0x68567739bd4f190697d9305da326fa28ef711443d08a390a05008a8afe822103. -// -// Solidity: event ParamsUpdated((uint256,uint256,uint256,uint256,uint256) params) -func (_DASigners *DASignersFilterer) WatchParamsUpdated(opts *bind.WatchOpts, sink chan<- *DASignersParamsUpdated) (event.Subscription, error) { - - logs, sub, err := _DASigners.contract.WatchLogs(opts, "ParamsUpdated") - if err != nil { - return nil, err - } - return event.NewSubscription(func(quit <-chan struct{}) error { - defer sub.Unsubscribe() - for { - select { - case log := <-logs: - // New log arrived, parse the event and forward to the user - event := new(DASignersParamsUpdated) - if err := _DASigners.contract.UnpackLog(event, "ParamsUpdated", log); err != nil { - return err - } - event.Raw = log - - select { - case sink <- event: - case err := <-sub.Err(): - return err - case <-quit: - return nil - } - case err := <-sub.Err(): - return err - case <-quit: - return nil - } - } - }), nil -} - -// ParseParamsUpdated is a log parse operation binding the contract event 0x68567739bd4f190697d9305da326fa28ef711443d08a390a05008a8afe822103. -// -// Solidity: event ParamsUpdated((uint256,uint256,uint256,uint256,uint256) params) -func (_DASigners *DASignersFilterer) ParseParamsUpdated(log types.Log) (*DASignersParamsUpdated, error) { - event := new(DASignersParamsUpdated) - if err := _DASigners.contract.UnpackLog(event, "ParamsUpdated", log); err != nil { - return nil, err - } - event.Raw = log - return event, nil -} - // DASignersSocketUpdatedIterator is returned from FilterSocketUpdated and is used to iterate over the raw logs and unpacked data for SocketUpdated events raised by the DASigners contract. type DASignersSocketUpdatedIterator struct { Event *DASignersSocketUpdated // Event containing the contract specifics and raw log diff --git a/precompiles/dasigners/dasigners_test.go b/precompiles/dasigners/dasigners_test.go index 4ed52dd8..b36ef7d1 100644 --- a/precompiles/dasigners/dasigners_test.go +++ b/precompiles/dasigners/dasigners_test.go @@ -370,6 +370,25 @@ func (suite *DASignersTestSuite) Test_DASigners() { } +func (suite *DASignersTestSuite) Test_Params() { + input, err := suite.abi.Pack( + "params", + ) + suite.Assert().NoError(err) + + bz, err := suite.runTx(input, suite.signerOne, 10000000) + suite.Assert().NoError(err) + out, err := suite.abi.Methods["params"].Outputs.Unpack(bz) + suite.Assert().NoError(err) + params := out[0].(dasignersprecompile.IDASignersParams) + expected := types.DefaultGenesisState().Params + suite.Assert().EqualValues(expected.TokensPerVote, params.TokensPerVote.Uint64()) + suite.Assert().EqualValues(expected.MaxVotesPerSigner, params.MaxVotesPerSigner.Uint64()) + suite.Assert().EqualValues(expected.MaxQuorums, params.MaxQuorums.Uint64()) + suite.Assert().EqualValues(expected.EpochBlocks, params.EpochBlocks.Uint64()) + suite.Assert().EqualValues(expected.EncodedSlices, params.EncodedSlices.Uint64()) +} + func TestKeeperSuite(t *testing.T) { suite.Run(t, new(DASignersTestSuite)) } diff --git a/precompiles/dasigners/types.go b/precompiles/dasigners/types.go index 1acf2251..fdda79ca 100644 --- a/precompiles/dasigners/types.go +++ b/precompiles/dasigners/types.go @@ -27,7 +27,7 @@ type IDASignersSignerDetail = struct { PkG2 BN254G2Point "json:\"pkG2\"" } -type IDASignersParams struct { +type IDASignersParams = struct { TokensPerVote *big.Int "json:\"tokensPerVote\"" MaxVotesPerSigner *big.Int "json:\"maxVotesPerSigner\"" MaxQuorums *big.Int "json:\"maxQuorums\"" diff --git a/x/dasigners/v1/keeper/msg_server_test.go b/x/dasigners/v1/keeper/msg_server_test.go new file mode 100644 index 00000000..d6934ba6 --- /dev/null +++ b/x/dasigners/v1/keeper/msg_server_test.go @@ -0,0 +1,71 @@ +package keeper_test + +import ( + "testing" + + "github.com/0glabs/0g-chain/x/dasigners/v1/testutil" + "github.com/0glabs/0g-chain/x/dasigners/v1/types" + "github.com/stretchr/testify/suite" +) + +type MsgServerTestSuite struct { + testutil.Suite +} + +func (suite *MsgServerTestSuite) TestChangeParams() { + govAccAddr := suite.GovKeeper.GetGovernanceAccount(suite.Ctx).GetAddress().String() + + testCases := []struct { + name string + req *types.MsgChangeParams + expectErr bool + errMsg string + }{ + { + name: "invalid signer", + req: &types.MsgChangeParams{ + Authority: suite.Addresses[0].String(), + Params: &types.Params{ + TokensPerVote: 10, + MaxVotesPerSigner: 1024, + MaxQuorums: 10, + EpochBlocks: 5760, + EncodedSlices: 3072, + }, + }, + expectErr: true, + errMsg: "expected gov account as only signer for proposal message", + }, + { + name: "success", + req: &types.MsgChangeParams{ + Authority: govAccAddr, + Params: &types.Params{ + TokensPerVote: 1, + MaxVotesPerSigner: 2048, + MaxQuorums: 1, + EpochBlocks: 100, + EncodedSlices: 2048 * 3, + }, + }, + expectErr: false, + }, + } + for _, tc := range testCases { + suite.Run(tc.name, func() { + _, err := suite.Keeper.ChangeParams(suite.Ctx, tc.req) + if tc.expectErr { + suite.Require().Error(err) + suite.Require().Contains(err.Error(), tc.errMsg) + } else { + suite.Require().NoError(err) + params := suite.Keeper.GetParams(suite.Ctx) + suite.Require().EqualValues(*tc.req.Params, params) + } + }) + } +} + +func TestMsgServerSuite(t *testing.T) { + suite.Run(t, new(MsgServerTestSuite)) +} diff --git a/x/dasigners/v1/testutil/suite.go b/x/dasigners/v1/testutil/suite.go index 1191cba7..229fa7a2 100644 --- a/x/dasigners/v1/testutil/suite.go +++ b/x/dasigners/v1/testutil/suite.go @@ -14,6 +14,7 @@ import ( "github.com/0glabs/0g-chain/chaincfg" "github.com/0glabs/0g-chain/x/dasigners/v1/keeper" "github.com/0glabs/0g-chain/x/dasigners/v1/types" + govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/evmos/ethermint/crypto/ethsecp256k1" ) @@ -24,6 +25,7 @@ type Suite struct { Keeper keeper.Keeper StakingKeeper *stakingkeeper.Keeper + GovKeeper govkeeper.Keeper App app.TestApp Ctx sdk.Context QueryClient types.QueryClient @@ -37,6 +39,7 @@ func (suite *Suite) SetupTest() { suite.App.InitializeFromGenesisStates() suite.Keeper = suite.App.GetDASignersKeeper() suite.StakingKeeper = suite.App.GetStakingKeeper() + suite.GovKeeper = suite.App.GetGovKeeper() // make block header privkey, _ := ethsecp256k1.GenerateKey()