[availability] Count availability for shard chain, more log, remove error of div by zero as error condition (#2342)
* [availability] More log, remove error of div by zero * [availability] Apply increment of count in accumulate since need crosslink * [availability] More log * [staking] VC easy flow of create validator and delegation, restart watchdog * [availability] Use method instead of inline, fix Cmp mistake in measure * [availability] Add explicit log for measure * [availability] Begin unit test impl * [availability] Factor out subset of methods that availability needs, expand test * [availability] Do not increment count when LastEpochInCommittee is 0 * [availability] Remove dev scripts * [availability] Adjust logs * [availability] Remove test BLS keys * [availability] Remove check on LastEpoch in bumpCount, remove spurious log * [availability] Further simplify, current shard state is the elected validator * [consensus] Remove log * [project] Remove noisy, hard to know where happened log; whitespace on stylepull/2355/head
parent
c653234ca8
commit
2e27e1b845
@ -0,0 +1,66 @@ |
|||||||
|
package availability |
||||||
|
|
||||||
|
import ( |
||||||
|
"math/big" |
||||||
|
"testing" |
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common" |
||||||
|
"github.com/ethereum/go-ethereum/ethdb" |
||||||
|
"github.com/harmony-one/harmony/core/state" |
||||||
|
common2 "github.com/harmony-one/harmony/internal/common" |
||||||
|
staking "github.com/harmony-one/harmony/staking/types" |
||||||
|
) |
||||||
|
|
||||||
|
type fakerAuctioneer struct{} |
||||||
|
|
||||||
|
const ( |
||||||
|
to0 = "one1zyxauxquys60dk824p532jjdq753pnsenrgmef" |
||||||
|
to2 = "one14438psd5vrjes7qm97jrj3t0s5l4qff5j5cn4h" |
||||||
|
) |
||||||
|
|
||||||
|
var ( |
||||||
|
validatorS0Addr, validatorS2Addr = common.Address{}, common.Address{} |
||||||
|
addrs = []common.Address{} |
||||||
|
validatorS0, validatorS2 = &staking.ValidatorWrapper{}, &staking.ValidatorWrapper{} |
||||||
|
) |
||||||
|
|
||||||
|
func init() { |
||||||
|
validatorS0Addr, _ = common2.Bech32ToAddress(to0) |
||||||
|
validatorS2Addr, _ = common2.Bech32ToAddress(to2) |
||||||
|
addrs = []common.Address{validatorS0Addr, validatorS2Addr} |
||||||
|
} |
||||||
|
|
||||||
|
func (fakerAuctioneer) ReadValidatorSnapshot( |
||||||
|
addr common.Address, |
||||||
|
) (*staking.ValidatorWrapper, error) { |
||||||
|
switch addr { |
||||||
|
case validatorS0Addr: |
||||||
|
return validatorS0, nil |
||||||
|
case validatorS2Addr: |
||||||
|
return validatorS0, nil |
||||||
|
default: |
||||||
|
panic("bad input in test case") |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func defaultStateWithAccountsApplied() *state.DB { |
||||||
|
st := ethdb.NewMemDatabase() |
||||||
|
stateHandle, _ := state.New(common.Hash{}, state.NewDatabase(st)) |
||||||
|
for _, addr := range addrs { |
||||||
|
stateHandle.CreateAccount(addr) |
||||||
|
} |
||||||
|
stateHandle.SetBalance(validatorS0Addr, big.NewInt(0).SetUint64(1994680320000000000)) |
||||||
|
stateHandle.SetBalance(validatorS2Addr, big.NewInt(0).SetUint64(1999975592000000000)) |
||||||
|
return stateHandle |
||||||
|
} |
||||||
|
|
||||||
|
func TestSetInactiveUnavailableValidators(t *testing.T) { |
||||||
|
state := defaultStateWithAccountsApplied() |
||||||
|
if err := SetInactiveUnavailableValidators( |
||||||
|
fakerAuctioneer{}, state, addrs, |
||||||
|
); err != nil { |
||||||
|
//
|
||||||
|
} |
||||||
|
|
||||||
|
t.Log("Unimplemented") |
||||||
|
} |
Loading…
Reference in new issue