How to use Equal method of got Package

Best Got code snippet using got.Equal

handler_test.go

Source:handler_test.go Github

copy

Full Screen

...48 // verify the self-delegation exists49 bond, found := keeper.GetDelegation(ctx, validatorAddr, validatorAddr)50 require.True(t, found)51 gotBond := bond.Shares.RoundInt64()52 require.Equal(t, initBond, gotBond,53 "initBond: %v\ngotBond: %v\nbond: %v\n",54 initBond, gotBond, bond)55 // verify that the by power index exists56 validator, found := keeper.GetValidator(ctx, validatorAddr)57 require.True(t, found)58 pool := keeper.GetPool(ctx)59 power := keep.GetValidatorsByPowerIndexKey(validator, pool)60 require.True(t, keep.ValidatorByPowerIndexExists(ctx, keeper, power))61 // create a second validator keep it bonded62 msgCreateValidator = newTestMsgCreateValidator(validatorAddr3, keep.PKs[2], int64(1000000))63 got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)64 require.True(t, got.IsOK(), "expected create-validator to be ok, got %v", got)65 // slash and revoke the first validator66 keeper.Slash(ctx, keep.PKs[0], 0, initBond, sdk.NewRat(1, 2))67 keeper.Revoke(ctx, keep.PKs[0])68 validator, found = keeper.GetValidator(ctx, validatorAddr)69 require.True(t, found)70 require.Equal(t, sdk.Unbonded, validator.Status) // ensure is unbonded71 require.Equal(t, int64(500000), validator.Tokens.RoundInt64()) // ensure is unbonded72 // the old power record should have been deleted as the power changed73 require.False(t, keep.ValidatorByPowerIndexExists(ctx, keeper, power))74 // but the new power record should have been created75 validator, found = keeper.GetValidator(ctx, validatorAddr)76 require.True(t, found)77 pool = keeper.GetPool(ctx)78 power2 := GetValidatorsByPowerIndexKey(validator, pool)79 require.True(t, keep.ValidatorByPowerIndexExists(ctx, keeper, power2))80 // inflate a bunch81 params := keeper.GetParams(ctx)82 for i := 0; i < 200; i++ {83 pool = pool.ProcessProvisions(params)84 keeper.SetPool(ctx, pool)85 }86 // now the new record power index should be the same as the original record87 power3 := GetValidatorsByPowerIndexKey(validator, pool)88 require.Equal(t, power2, power3)89 // unbond self-delegation90 msgBeginUnbonding := NewMsgBeginUnbonding(validatorAddr, validatorAddr, sdk.NewRat(1000000))91 msgCompleteUnbonding := NewMsgCompleteUnbonding(validatorAddr, validatorAddr)92 got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper)93 require.True(t, got.IsOK(), "expected msg to be ok, got %v", got)94 got = handleMsgCompleteUnbonding(ctx, msgCompleteUnbonding, keeper)95 require.True(t, got.IsOK(), "expected msg to be ok, got %v", got)96 // verify that by power key nolonger exists97 _, found = keeper.GetValidator(ctx, validatorAddr)98 require.False(t, found)99 require.False(t, keep.ValidatorByPowerIndexExists(ctx, keeper, power3))100}101func TestDuplicatesMsgCreateValidator(t *testing.T) {102 ctx, _, keeper := keep.CreateTestInput(t, false, 1000)103 addr1, addr2 := keep.Addrs[0], keep.Addrs[1]104 pk1, pk2 := keep.PKs[0], keep.PKs[1]105 msgCreateValidator1 := newTestMsgCreateValidator(addr1, pk1, 10)106 got := handleMsgCreateValidator(ctx, msgCreateValidator1, keeper)107 require.True(t, got.IsOK(), "%v", got)108 validator, found := keeper.GetValidator(ctx, addr1)109 require.True(t, found)110 assert.Equal(t, sdk.Bonded, validator.Status)111 assert.Equal(t, addr1, validator.Owner)112 assert.Equal(t, pk1, validator.PubKey)113 assert.Equal(t, sdk.NewRat(10), validator.BondedTokens())114 assert.Equal(t, sdk.NewRat(10), validator.DelegatorShares)115 assert.Equal(t, Description{}, validator.Description)116 // two validators can't have the same owner address117 msgCreateValidator2 := newTestMsgCreateValidator(addr1, pk2, 10)118 got = handleMsgCreateValidator(ctx, msgCreateValidator2, keeper)119 require.False(t, got.IsOK(), "%v", got)120 // two validators can't have the same pubkey121 msgCreateValidator3 := newTestMsgCreateValidator(addr2, pk1, 10)122 got = handleMsgCreateValidator(ctx, msgCreateValidator3, keeper)123 require.False(t, got.IsOK(), "%v", got)124 // must have different pubkey and owner125 msgCreateValidator4 := newTestMsgCreateValidator(addr2, pk2, 10)126 got = handleMsgCreateValidator(ctx, msgCreateValidator4, keeper)127 require.True(t, got.IsOK(), "%v", got)128 validator, found = keeper.GetValidator(ctx, addr2)129 require.True(t, found)130 assert.Equal(t, sdk.Bonded, validator.Status)131 assert.Equal(t, addr2, validator.Owner)132 assert.Equal(t, pk2, validator.PubKey)133 assert.True(sdk.RatEq(t, sdk.NewRat(10), validator.Tokens))134 assert.True(sdk.RatEq(t, sdk.NewRat(10), validator.DelegatorShares))135 assert.Equal(t, Description{}, validator.Description)136}137func TestDuplicatesMsgCreateValidatorOnBehalfOf(t *testing.T) {138 ctx, _, keeper := keep.CreateTestInput(t, false, 1000)139 validatorAddr := keep.Addrs[0]140 delegatorAddr := keep.Addrs[1]141 pk := keep.PKs[0]142 msgCreateValidatorOnBehalfOf := newTestMsgCreateValidatorOnBehalfOf(delegatorAddr, validatorAddr, pk, 10)143 got := handleMsgCreateValidator(ctx, msgCreateValidatorOnBehalfOf, keeper)144 require.True(t, got.IsOK(), "%v", got)145 validator, found := keeper.GetValidator(ctx, validatorAddr)146 require.True(t, found)147 assert.Equal(t, sdk.Bonded, validator.Status)148 assert.Equal(t, validatorAddr, validator.Owner)149 assert.Equal(t, pk, validator.PubKey)150 assert.True(sdk.RatEq(t, sdk.NewRat(10), validator.Tokens))151 assert.True(sdk.RatEq(t, sdk.NewRat(10), validator.DelegatorShares))152 assert.Equal(t, Description{}, validator.Description)153 // one validator cannot be created twice even from different delegator154 msgCreateValidatorOnBehalfOf.DelegatorAddr = keep.Addrs[2]155 msgCreateValidatorOnBehalfOf.PubKey = keep.PKs[1]156 got = handleMsgCreateValidator(ctx, msgCreateValidatorOnBehalfOf, keeper)157 require.False(t, got.IsOK(), "%v", got)158}159func TestIncrementsMsgDelegate(t *testing.T) {160 initBond := int64(1000)161 ctx, accMapper, keeper := keep.CreateTestInput(t, false, initBond)162 params := keeper.GetParams(ctx)163 bondAmount := int64(10)164 validatorAddr, delegatorAddr := keep.Addrs[0], keep.Addrs[1]165 // first create validator166 msgCreateValidator := newTestMsgCreateValidator(validatorAddr, keep.PKs[0], bondAmount)167 got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)168 require.True(t, got.IsOK(), "expected create validator msg to be ok, got %v", got)169 validator, found := keeper.GetValidator(ctx, validatorAddr)170 require.True(t, found)171 require.Equal(t, sdk.Bonded, validator.Status)172 require.Equal(t, bondAmount, validator.DelegatorShares.RoundInt64())173 require.Equal(t, bondAmount, validator.BondedTokens().RoundInt64(), "validator: %v", validator)174 _, found = keeper.GetDelegation(ctx, delegatorAddr, validatorAddr)175 require.False(t, found)176 bond, found := keeper.GetDelegation(ctx, validatorAddr, validatorAddr)177 require.True(t, found)178 require.Equal(t, bondAmount, bond.Shares.RoundInt64())179 pool := keeper.GetPool(ctx)180 exRate := validator.DelegatorShareExRate()181 require.True(t, exRate.Equal(sdk.OneRat()), "expected exRate 1 got %v", exRate)182 require.Equal(t, bondAmount, pool.BondedTokens.RoundInt64())183 // just send the same msgbond multiple times184 msgDelegate := newTestMsgDelegate(delegatorAddr, validatorAddr, bondAmount)185 for i := 0; i < 5; i++ {186 ctx = ctx.WithBlockHeight(int64(i))187 got := handleMsgDelegate(ctx, msgDelegate, keeper)188 require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)189 //Check that the accounts and the bond account have the appropriate values190 validator, found := keeper.GetValidator(ctx, validatorAddr)191 require.True(t, found)192 bond, found := keeper.GetDelegation(ctx, delegatorAddr, validatorAddr)193 require.True(t, found)194 exRate := validator.DelegatorShareExRate()195 require.True(t, exRate.Equal(sdk.OneRat()), "expected exRate 1 got %v, i = %v", exRate, i)196 expBond := int64(i+1) * bondAmount197 expDelegatorShares := int64(i+2) * bondAmount // (1 self delegation)198 expDelegatorAcc := sdk.NewInt(initBond - expBond)199 require.Equal(t, bond.Height, int64(i), "Incorrect bond height")200 gotBond := bond.Shares.RoundInt64()201 gotDelegatorShares := validator.DelegatorShares.RoundInt64()202 gotDelegatorAcc := accMapper.GetAccount(ctx, delegatorAddr).GetCoins().AmountOf(params.BondDenom)203 require.Equal(t, expBond, gotBond,204 "i: %v\nexpBond: %v\ngotBond: %v\nvalidator: %v\nbond: %v\n",205 i, expBond, gotBond, validator, bond)206 require.Equal(t, expDelegatorShares, gotDelegatorShares,207 "i: %v\nexpDelegatorShares: %v\ngotDelegatorShares: %v\nvalidator: %v\nbond: %v\n",208 i, expDelegatorShares, gotDelegatorShares, validator, bond)209 require.Equal(t, expDelegatorAcc, gotDelegatorAcc,210 "i: %v\nexpDelegatorAcc: %v\ngotDelegatorAcc: %v\nvalidator: %v\nbond: %v\n",211 i, expDelegatorAcc, gotDelegatorAcc, validator, bond)212 }213}214func TestIncrementsMsgUnbond(t *testing.T) {215 initBond := int64(1000)216 ctx, accMapper, keeper := keep.CreateTestInput(t, false, initBond)217 params := setInstantUnbondPeriod(keeper, ctx)218 denom := params.BondDenom219 // create validator, delegate220 validatorAddr, delegatorAddr := keep.Addrs[0], keep.Addrs[1]221 msgCreateValidator := newTestMsgCreateValidator(validatorAddr, keep.PKs[0], initBond)222 got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)223 require.True(t, got.IsOK(), "expected create-validator to be ok, got %v", got)224 // initial balance225 amt1 := accMapper.GetAccount(ctx, delegatorAddr).GetCoins().AmountOf(denom)226 msgDelegate := newTestMsgDelegate(delegatorAddr, validatorAddr, initBond)227 got = handleMsgDelegate(ctx, msgDelegate, keeper)228 require.True(t, got.IsOK(), "expected delegation to be ok, got %v", got)229 // balance should have been subtracted after delegation230 amt2 := accMapper.GetAccount(ctx, delegatorAddr).GetCoins().AmountOf(denom)231 require.Equal(t, amt1.Sub(sdk.NewInt(initBond)).Int64(), amt2.Int64(), "expected coins to be subtracted")232 validator, found := keeper.GetValidator(ctx, validatorAddr)233 require.True(t, found)234 require.Equal(t, initBond*2, validator.DelegatorShares.RoundInt64())235 require.Equal(t, initBond*2, validator.BondedTokens().RoundInt64())236 // just send the same msgUnbond multiple times237 // TODO use decimals here238 unbondShares := sdk.NewRat(10)239 msgBeginUnbonding := NewMsgBeginUnbonding(delegatorAddr, validatorAddr, unbondShares)240 msgCompleteUnbonding := NewMsgCompleteUnbonding(delegatorAddr, validatorAddr)241 numUnbonds := 5242 for i := 0; i < numUnbonds; i++ {243 got := handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper)244 require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)245 got = handleMsgCompleteUnbonding(ctx, msgCompleteUnbonding, keeper)246 require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)247 //Check that the accounts and the bond account have the appropriate values248 validator, found = keeper.GetValidator(ctx, validatorAddr)249 require.True(t, found)250 bond, found := keeper.GetDelegation(ctx, delegatorAddr, validatorAddr)251 require.True(t, found)252 expBond := initBond - int64(i+1)*unbondShares.RoundInt64()253 expDelegatorShares := 2*initBond - int64(i+1)*unbondShares.RoundInt64()254 expDelegatorAcc := sdk.NewInt(initBond - expBond)255 gotBond := bond.Shares.RoundInt64()256 gotDelegatorShares := validator.DelegatorShares.RoundInt64()257 gotDelegatorAcc := accMapper.GetAccount(ctx, delegatorAddr).GetCoins().AmountOf(params.BondDenom)258 require.Equal(t, expBond, gotBond,259 "i: %v\nexpBond: %v\ngotBond: %v\nvalidator: %v\nbond: %v\n",260 i, expBond, gotBond, validator, bond)261 require.Equal(t, expDelegatorShares, gotDelegatorShares,262 "i: %v\nexpDelegatorShares: %v\ngotDelegatorShares: %v\nvalidator: %v\nbond: %v\n",263 i, expDelegatorShares, gotDelegatorShares, validator, bond)264 require.Equal(t, expDelegatorAcc, gotDelegatorAcc,265 "i: %v\nexpDelegatorAcc: %v\ngotDelegatorAcc: %v\nvalidator: %v\nbond: %v\n",266 i, expDelegatorAcc, gotDelegatorAcc, validator, bond)267 }268 // these are more than we have bonded now269 errorCases := []int64{270 //1<<64 - 1, // more than int64271 //1<<63 + 1, // more than int64272 1<<63 - 1,273 1 << 31,274 initBond,275 }276 for _, c := range errorCases {277 unbondShares := sdk.NewRat(int64(c))278 msgBeginUnbonding := NewMsgBeginUnbonding(delegatorAddr, validatorAddr, unbondShares)279 got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper)280 require.False(t, got.IsOK(), "expected unbond msg to fail")281 }282 leftBonded := initBond - int64(numUnbonds)*unbondShares.RoundInt64()283 // should be unable to unbond one more than we have284 unbondShares = sdk.NewRat(leftBonded + 1)285 msgBeginUnbonding = NewMsgBeginUnbonding(delegatorAddr, validatorAddr, unbondShares)286 got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper)287 require.False(t, got.IsOK(),288 "got: %v\nmsgUnbond: %v\nshares: %v\nleftBonded: %v\n", got, msgBeginUnbonding, unbondShares.String(), leftBonded)289 // should be able to unbond just what we have290 unbondShares = sdk.NewRat(leftBonded)291 msgBeginUnbonding = NewMsgBeginUnbonding(delegatorAddr, validatorAddr, unbondShares)292 got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper)293 require.True(t, got.IsOK(),294 "got: %v\nmsgUnbond: %v\nshares: %v\nleftBonded: %v\n", got, msgBeginUnbonding, unbondShares, leftBonded)295}296func TestMultipleMsgCreateValidator(t *testing.T) {297 initBond := int64(1000)298 ctx, accMapper, keeper := keep.CreateTestInput(t, false, initBond)299 params := setInstantUnbondPeriod(keeper, ctx)300 validatorAddrs := []sdk.AccAddress{keep.Addrs[0], keep.Addrs[1], keep.Addrs[2]}301 delegatorAddrs := []sdk.AccAddress{keep.Addrs[3], keep.Addrs[4], keep.Addrs[5]}302 // bond them all303 for i, validatorAddr := range validatorAddrs {304 msgCreateValidatorOnBehalfOf := newTestMsgCreateValidatorOnBehalfOf(delegatorAddrs[i], validatorAddr, keep.PKs[i], 10)305 got := handleMsgCreateValidator(ctx, msgCreateValidatorOnBehalfOf, keeper)306 require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)307 //Check that the account is bonded308 validators := keeper.GetValidators(ctx, 100)309 require.Equal(t, (i + 1), len(validators))310 val := validators[i]311 balanceExpd := sdk.NewInt(initBond - 10)312 balanceGot := accMapper.GetAccount(ctx, delegatorAddrs[i]).GetCoins().AmountOf(params.BondDenom)313 require.Equal(t, i+1, len(validators), "expected %d validators got %d, validators: %v", i+1, len(validators), validators)314 require.Equal(t, 10, int(val.DelegatorShares.RoundInt64()), "expected %d shares, got %d", 10, val.DelegatorShares)315 require.Equal(t, balanceExpd, balanceGot, "expected account to have %d, got %d", balanceExpd, balanceGot)316 }317 // unbond them all by revoking delegation318 for i, validatorAddr := range validatorAddrs {319 _, found := keeper.GetValidator(ctx, validatorAddr)320 require.True(t, found)321 msgBeginUnbonding := NewMsgBeginUnbonding(delegatorAddrs[i], validatorAddr, sdk.NewRat(10)) // remove delegation322 msgCompleteUnbonding := NewMsgCompleteUnbonding(delegatorAddrs[i], validatorAddr)323 got := handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper)324 require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)325 got = handleMsgCompleteUnbonding(ctx, msgCompleteUnbonding, keeper)326 require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)327 //Check that the account is unbonded328 validators := keeper.GetValidators(ctx, 100)329 require.Equal(t, len(validatorAddrs)-(i+1), len(validators),330 "expected %d validators got %d", len(validatorAddrs)-(i+1), len(validators))331 _, found = keeper.GetValidator(ctx, validatorAddr)332 require.False(t, found)333 expBalance := sdk.NewInt(initBond)334 gotBalance := accMapper.GetAccount(ctx, delegatorAddrs[i]).GetCoins().AmountOf(params.BondDenom)335 require.Equal(t, expBalance, gotBalance, "expected account to have %d, got %d", expBalance, gotBalance)336 }337}338func TestMultipleMsgDelegate(t *testing.T) {339 ctx, _, keeper := keep.CreateTestInput(t, false, 1000)340 validatorAddr, delegatorAddrs := keep.Addrs[0], keep.Addrs[1:]341 _ = setInstantUnbondPeriod(keeper, ctx)342 //first make a validator343 msgCreateValidator := newTestMsgCreateValidator(validatorAddr, keep.PKs[0], 10)344 got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)345 require.True(t, got.IsOK(), "expected msg to be ok, got %v", got)346 // delegate multiple parties347 for i, delegatorAddr := range delegatorAddrs {348 msgDelegate := newTestMsgDelegate(delegatorAddr, validatorAddr, 10)349 got := handleMsgDelegate(ctx, msgDelegate, keeper)350 require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)351 //Check that the account is bonded352 bond, found := keeper.GetDelegation(ctx, delegatorAddr, validatorAddr)353 require.True(t, found)354 require.NotNil(t, bond, "expected delegatee bond %d to exist", bond)355 }356 // unbond them all357 for i, delegatorAddr := range delegatorAddrs {358 msgBeginUnbonding := NewMsgBeginUnbonding(delegatorAddr, validatorAddr, sdk.NewRat(10))359 msgCompleteUnbonding := NewMsgCompleteUnbonding(delegatorAddr, validatorAddr)360 got := handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper)361 require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)362 got = handleMsgCompleteUnbonding(ctx, msgCompleteUnbonding, keeper)363 require.True(t, got.IsOK(), "expected msg %d to be ok, got %v", i, got)364 //Check that the account is unbonded365 _, found := keeper.GetDelegation(ctx, delegatorAddr, validatorAddr)366 require.False(t, found)367 }368}369func TestRevokeValidator(t *testing.T) {370 ctx, _, keeper := keep.CreateTestInput(t, false, 1000)371 validatorAddr, delegatorAddr := keep.Addrs[0], keep.Addrs[1]372 _ = setInstantUnbondPeriod(keeper, ctx)373 // create the validator374 msgCreateValidator := newTestMsgCreateValidator(validatorAddr, keep.PKs[0], 10)375 got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)376 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")377 // bond a delegator378 msgDelegate := newTestMsgDelegate(delegatorAddr, validatorAddr, 10)379 got = handleMsgDelegate(ctx, msgDelegate, keeper)380 require.True(t, got.IsOK(), "expected ok, got %v", got)381 validator, _ := keeper.GetValidator(ctx, validatorAddr)382 // unbond the validators bond portion383 msgBeginUnbondingValidator := NewMsgBeginUnbonding(validatorAddr, validatorAddr, sdk.NewRat(10))384 msgCompleteUnbondingValidator := NewMsgCompleteUnbonding(validatorAddr, validatorAddr)385 got = handleMsgBeginUnbonding(ctx, msgBeginUnbondingValidator, keeper)386 require.True(t, got.IsOK(), "expected no error")387 got = handleMsgCompleteUnbonding(ctx, msgCompleteUnbondingValidator, keeper)388 require.True(t, got.IsOK(), "expected no error")389 validator, found := keeper.GetValidator(ctx, validatorAddr)390 require.True(t, found)391 require.True(t, validator.Revoked, "%v", validator)392 // test that this address cannot yet be bonded too because is revoked393 got = handleMsgDelegate(ctx, msgDelegate, keeper)394 require.False(t, got.IsOK(), "expected error, got %v", got)395 // test that the delegator can still withdraw their bonds396 msgBeginUnbondingDelegator := NewMsgBeginUnbonding(delegatorAddr, validatorAddr, sdk.NewRat(10))397 msgCompleteUnbondingDelegator := NewMsgCompleteUnbonding(delegatorAddr, validatorAddr)398 got = handleMsgBeginUnbonding(ctx, msgBeginUnbondingDelegator, keeper)399 require.True(t, got.IsOK(), "expected no error")400 got = handleMsgCompleteUnbonding(ctx, msgCompleteUnbondingDelegator, keeper)401 require.True(t, got.IsOK(), "expected no error")402 // verify that the pubkey can now be reused403 got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)404 require.True(t, got.IsOK(), "expected ok, got %v", got)405}406func TestUnbondingPeriod(t *testing.T) {407 ctx, _, keeper := keep.CreateTestInput(t, false, 1000)408 validatorAddr := keep.Addrs[0]409 // set the unbonding time410 params := keeper.GetParams(ctx)411 params.UnbondingTime = 7412 keeper.SetParams(ctx, params)413 // create the validator414 msgCreateValidator := newTestMsgCreateValidator(validatorAddr, keep.PKs[0], 10)415 got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)416 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")417 // begin unbonding418 msgBeginUnbonding := NewMsgBeginUnbonding(validatorAddr, validatorAddr, sdk.NewRat(10))419 got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper)420 require.True(t, got.IsOK(), "expected no error")421 // cannot complete unbonding at same time422 msgCompleteUnbonding := NewMsgCompleteUnbonding(validatorAddr, validatorAddr)423 got = handleMsgCompleteUnbonding(ctx, msgCompleteUnbonding, keeper)424 require.True(t, !got.IsOK(), "expected no error")425 // cannot complete unbonding at time 6 seconds later426 origHeader := ctx.BlockHeader()427 headerTime6 := origHeader428 headerTime6.Time += 6429 ctx = ctx.WithBlockHeader(headerTime6)430 got = handleMsgCompleteUnbonding(ctx, msgCompleteUnbonding, keeper)431 require.True(t, !got.IsOK(), "expected no error")432 // can complete unbonding at time 7 seconds later433 headerTime7 := origHeader434 headerTime7.Time += 7435 ctx = ctx.WithBlockHeader(headerTime7)436 got = handleMsgCompleteUnbonding(ctx, msgCompleteUnbonding, keeper)437 require.True(t, got.IsOK(), "expected no error")438}439func TestRedelegationPeriod(t *testing.T) {440 ctx, AccMapper, keeper := keep.CreateTestInput(t, false, 1000)441 validatorAddr, validatorAddr2 := keep.Addrs[0], keep.Addrs[1]442 denom := keeper.GetParams(ctx).BondDenom443 // set the unbonding time444 params := keeper.GetParams(ctx)445 params.UnbondingTime = 7446 keeper.SetParams(ctx, params)447 // create the validators448 msgCreateValidator := newTestMsgCreateValidator(validatorAddr, keep.PKs[0], 10)449 // initial balance450 amt1 := AccMapper.GetAccount(ctx, validatorAddr).GetCoins().AmountOf(denom)451 got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)452 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")453 // balance should have been subtracted after creation454 amt2 := AccMapper.GetAccount(ctx, validatorAddr).GetCoins().AmountOf(denom)455 require.Equal(t, amt1.Sub(sdk.NewInt(10)).Int64(), amt2.Int64(), "expected coins to be subtracted")456 msgCreateValidator = newTestMsgCreateValidator(validatorAddr2, keep.PKs[1], 10)457 got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)458 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")459 bal1 := AccMapper.GetAccount(ctx, validatorAddr).GetCoins()460 // begin redelegate461 msgBeginRedelegate := NewMsgBeginRedelegate(validatorAddr, validatorAddr, validatorAddr2, sdk.NewRat(10))462 got = handleMsgBeginRedelegate(ctx, msgBeginRedelegate, keeper)463 require.True(t, got.IsOK(), "expected no error, %v", got)464 // origin account should not lose tokens as with a regular delegation465 bal2 := AccMapper.GetAccount(ctx, validatorAddr).GetCoins()466 require.Equal(t, bal1, bal2)467 // cannot complete redelegation at same time468 msgCompleteRedelegate := NewMsgCompleteRedelegate(validatorAddr, validatorAddr, validatorAddr2)469 got = handleMsgCompleteRedelegate(ctx, msgCompleteRedelegate, keeper)470 require.True(t, !got.IsOK(), "expected an error")471 // cannot complete redelegation at time 6 seconds later472 origHeader := ctx.BlockHeader()473 headerTime6 := origHeader474 headerTime6.Time += 6475 ctx = ctx.WithBlockHeader(headerTime6)476 got = handleMsgCompleteRedelegate(ctx, msgCompleteRedelegate, keeper)477 require.True(t, !got.IsOK(), "expected an error")478 // can complete redelegation at time 7 seconds later479 headerTime7 := origHeader480 headerTime7.Time += 7481 ctx = ctx.WithBlockHeader(headerTime7)482 got = handleMsgCompleteRedelegate(ctx, msgCompleteRedelegate, keeper)483 require.True(t, got.IsOK(), "expected no error")484}485func TestTransitiveRedelegation(t *testing.T) {486 ctx, _, keeper := keep.CreateTestInput(t, false, 1000)487 validatorAddr, validatorAddr2, validatorAddr3 := keep.Addrs[0], keep.Addrs[1], keep.Addrs[2]488 // set the unbonding time489 params := keeper.GetParams(ctx)490 params.UnbondingTime = 0491 keeper.SetParams(ctx, params)492 // create the validators493 msgCreateValidator := newTestMsgCreateValidator(validatorAddr, keep.PKs[0], 10)494 got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)495 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")496 msgCreateValidator = newTestMsgCreateValidator(validatorAddr2, keep.PKs[1], 10)497 got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)498 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")499 msgCreateValidator = newTestMsgCreateValidator(validatorAddr3, keep.PKs[2], 10)500 got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)501 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")502 // begin redelegate503 msgBeginRedelegate := NewMsgBeginRedelegate(validatorAddr, validatorAddr, validatorAddr2, sdk.NewRat(10))504 got = handleMsgBeginRedelegate(ctx, msgBeginRedelegate, keeper)505 require.True(t, got.IsOK(), "expected no error, %v", got)506 // cannot redelegation to next validator while first delegation exists507 msgBeginRedelegate = NewMsgBeginRedelegate(validatorAddr, validatorAddr2, validatorAddr3, sdk.NewRat(10))508 got = handleMsgBeginRedelegate(ctx, msgBeginRedelegate, keeper)509 require.True(t, !got.IsOK(), "expected an error, msg: %v", msgBeginRedelegate)510 // complete first redelegation511 msgCompleteRedelegate := NewMsgCompleteRedelegate(validatorAddr, validatorAddr, validatorAddr2)512 got = handleMsgCompleteRedelegate(ctx, msgCompleteRedelegate, keeper)513 require.True(t, got.IsOK(), "expected no error")514 // now should be able to redelegate from the second validator to the third515 got = handleMsgBeginRedelegate(ctx, msgBeginRedelegate, keeper)516 require.True(t, got.IsOK(), "expected no error")517}518func TestUnbondingWhenExcessValidators(t *testing.T) {519 ctx, _, keeper := keep.CreateTestInput(t, false, 1000)520 validatorAddr1, validatorAddr2, validatorAddr3 := keep.Addrs[0], keep.Addrs[1], keep.Addrs[2]521 // set the unbonding time522 params := keeper.GetParams(ctx)523 params.UnbondingTime = 0524 params.MaxValidators = 2525 keeper.SetParams(ctx, params)526 // add three validators527 msgCreateValidator := newTestMsgCreateValidator(validatorAddr1, keep.PKs[0], 50)528 got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)529 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")530 require.Equal(t, 1, len(keeper.GetValidatorsBonded(ctx)))531 msgCreateValidator = newTestMsgCreateValidator(validatorAddr2, keep.PKs[1], 30)532 got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)533 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")534 require.Equal(t, 2, len(keeper.GetValidatorsBonded(ctx)))535 msgCreateValidator = newTestMsgCreateValidator(validatorAddr3, keep.PKs[2], 10)536 got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)537 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")538 require.Equal(t, 2, len(keeper.GetValidatorsBonded(ctx)))539 // unbond the valdator-2540 msgBeginUnbonding := NewMsgBeginUnbonding(validatorAddr2, validatorAddr2, sdk.NewRat(30))541 got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper)542 require.True(t, got.IsOK(), "expected no error on runMsgBeginUnbonding")543 // because there are extra validators waiting to get in, the queued544 // validator (aka. validator-1) should make it into the bonded group, thus545 // the total number of validators should stay the same546 vals := keeper.GetValidatorsBonded(ctx)547 require.Equal(t, 2, len(vals), "vals %v", vals)548 val1, found := keeper.GetValidator(ctx, validatorAddr1)549 require.True(t, found)550 require.Equal(t, sdk.Bonded, val1.Status, "%v", val1)551}552func TestJoiningAsCliffValidator(t *testing.T) {553 ctx, _, keeper := keep.CreateTestInput(t, false, 1000)554 validatorAddr1, validatorAddr2 := keep.Addrs[0], keep.Addrs[1]555 // make sure that the cliff validator is nil to begin with556 cliffVal := keeper.GetCliffValidator(ctx)557 require.Equal(t, []byte(nil), cliffVal)558 // set the unbonding time559 params := keeper.GetParams(ctx)560 params.UnbondingTime = 0561 params.MaxValidators = 2562 keeper.SetParams(ctx, params)563 // add the first validator564 msgCreateValidator := newTestMsgCreateValidator(validatorAddr1, keep.PKs[0], 50)565 got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)566 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")567 // cliff validator should still be nil568 cliffVal = keeper.GetCliffValidator(ctx)569 require.Equal(t, []byte(nil), cliffVal)570 // Add the second validator571 msgCreateValidator = newTestMsgCreateValidator(validatorAddr2, keep.PKs[1], 30)572 got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)573 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")574 // now that we've reached maximum validators, the val-2 should be added to the cliff (top)575 cliffVal = keeper.GetCliffValidator(ctx)576 require.Equal(t, validatorAddr2.Bytes(), cliffVal)577}578func TestJoiningToCreateFirstCliffValidator(t *testing.T) {579 ctx, _, keeper := keep.CreateTestInput(t, false, 1000)580 validatorAddr1, validatorAddr2 := keep.Addrs[0], keep.Addrs[1]581 // make sure that the cliff validator is nil to begin with582 cliffVal := keeper.GetCliffValidator(ctx)583 require.Equal(t, []byte(nil), cliffVal)584 // set the unbonding time585 params := keeper.GetParams(ctx)586 params.UnbondingTime = 0587 params.MaxValidators = 2588 keeper.SetParams(ctx, params)589 // add the first validator590 msgCreateValidator := newTestMsgCreateValidator(validatorAddr1, keep.PKs[0], 50)591 got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)592 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")593 // cliff validator should still be nil594 cliffVal = keeper.GetCliffValidator(ctx)595 require.Equal(t, []byte(nil), cliffVal)596 // Add the second validator597 msgCreateValidator = newTestMsgCreateValidator(validatorAddr2, keep.PKs[1], 60)598 got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)599 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")600 // now that we've reached maximum validators, validator-1 should be added to the cliff (top)601 cliffVal = keeper.GetCliffValidator(ctx)602 require.Equal(t, validatorAddr1.Bytes(), cliffVal)603}604func TestCliffValidator(t *testing.T) {605 ctx, _, keeper := keep.CreateTestInput(t, false, 1000)606 validatorAddr1, validatorAddr2, validatorAddr3 := keep.Addrs[0], keep.Addrs[1], keep.Addrs[2]607 // make sure that the cliff validator is nil to begin with608 cliffVal := keeper.GetCliffValidator(ctx)609 require.Equal(t, []byte(nil), cliffVal)610 // set the unbonding time611 params := keeper.GetParams(ctx)612 params.UnbondingTime = 0613 params.MaxValidators = 2614 keeper.SetParams(ctx, params)615 // add the first validator616 msgCreateValidator := newTestMsgCreateValidator(validatorAddr1, keep.PKs[0], 50)617 got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)618 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")619 // cliff validator should still be nil620 cliffVal = keeper.GetCliffValidator(ctx)621 require.Equal(t, []byte(nil), cliffVal)622 // Add the second validator623 msgCreateValidator = newTestMsgCreateValidator(validatorAddr2, keep.PKs[1], 30)624 got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)625 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")626 // now that we've reached maximum validators, validator-2 should be added to the cliff (top)627 cliffVal = keeper.GetCliffValidator(ctx)628 require.Equal(t, validatorAddr2.Bytes(), cliffVal)629 // add the third validator, which should not make it to being bonded,630 // so the cliff validator should not change because nobody has been kicked out631 msgCreateValidator = newTestMsgCreateValidator(validatorAddr3, keep.PKs[2], 10)632 got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)633 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")634 cliffVal = keeper.GetCliffValidator(ctx)635 require.Equal(t, validatorAddr2.Bytes(), cliffVal)636 // unbond valdator-2637 msgBeginUnbonding := NewMsgBeginUnbonding(validatorAddr2, validatorAddr2, sdk.NewRat(30))638 got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper)639 require.True(t, got.IsOK(), "expected no error on runMsgBeginUnbonding")640 vals := keeper.GetValidatorsBonded(ctx)641 require.Equal(t, 2, len(vals))642 // now the validator set should be updated,643 // where val-3 enters the validator set on the cliff644 cliffVal = keeper.GetCliffValidator(ctx)645 require.Equal(t, validatorAddr3.Bytes(), cliffVal)646 // unbond valdator-1647 msgBeginUnbonding = NewMsgBeginUnbonding(validatorAddr1, validatorAddr1, sdk.NewRat(50))648 got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper)649 require.True(t, got.IsOK(), "expected no error on runMsgBeginUnbonding")650 // get bonded validators - should just be one651 vals = keeper.GetValidatorsBonded(ctx)652 require.Equal(t, 1, len(vals))653 // cliff now should be empty654 cliffVal = keeper.GetCliffValidator(ctx)655 require.Equal(t, []byte(nil), cliffVal)656}657func TestBondUnbondRedelegateSlashTwice(t *testing.T) {658 ctx, _, keeper := keep.CreateTestInput(t, false, 1000)659 valA, valB, del := keep.Addrs[0], keep.Addrs[1], keep.Addrs[2]660 msgCreateValidator := newTestMsgCreateValidator(valA, keep.PKs[0], 10)661 got := handleMsgCreateValidator(ctx, msgCreateValidator, keeper)662 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")663 msgCreateValidator = newTestMsgCreateValidator(valB, keep.PKs[1], 10)664 got = handleMsgCreateValidator(ctx, msgCreateValidator, keeper)665 require.True(t, got.IsOK(), "expected no error on runMsgCreateValidator")666 // delegate 10 stake667 msgDelegate := newTestMsgDelegate(del, valA, 10)668 got = handleMsgDelegate(ctx, msgDelegate, keeper)669 require.True(t, got.IsOK(), "expected no error on runMsgDelegate")670 // a block passes671 ctx = ctx.WithBlockHeight(1)672 // begin unbonding 4 stake673 msgBeginUnbonding := NewMsgBeginUnbonding(del, valA, sdk.NewRat(4))674 got = handleMsgBeginUnbonding(ctx, msgBeginUnbonding, keeper)675 require.True(t, got.IsOK(), "expected no error on runMsgBeginUnbonding")676 // begin redelegate 6 stake677 msgBeginRedelegate := NewMsgBeginRedelegate(del, valA, valB, sdk.NewRat(6))678 got = handleMsgBeginRedelegate(ctx, msgBeginRedelegate, keeper)679 require.True(t, got.IsOK(), "expected no error on runMsgBeginRedelegate")680 // destination delegation should have 6 shares681 delegation, found := keeper.GetDelegation(ctx, del, valB)682 require.True(t, found)683 require.Equal(t, sdk.NewRat(6), delegation.Shares)684 // slash the validator by half685 keeper.Slash(ctx, keep.PKs[0], 0, 20, sdk.NewRat(1, 2))686 // unbonding delegation should have been slashed by half687 unbonding, found := keeper.GetUnbondingDelegation(ctx, del, valA)688 require.True(t, found)689 require.Equal(t, int64(2), unbonding.Balance.Amount.Int64())690 // redelegation should have been slashed by half691 redelegation, found := keeper.GetRedelegation(ctx, del, valA, valB)692 require.True(t, found)693 require.Equal(t, int64(3), redelegation.Balance.Amount.Int64())694 // destination delegation should have been slashed by half695 delegation, found = keeper.GetDelegation(ctx, del, valB)696 require.True(t, found)697 require.Equal(t, sdk.NewRat(3), delegation.Shares)698 // validator power should have been reduced by half699 validator, found := keeper.GetValidator(ctx, valA)700 require.True(t, found)701 require.Equal(t, sdk.NewRat(5), validator.GetPower())702 // slash the validator for an infraction committed after the unbonding and redelegation begin703 ctx = ctx.WithBlockHeight(3)704 keeper.Slash(ctx, keep.PKs[0], 2, 10, sdk.NewRat(1, 2))705 // unbonding delegation should be unchanged706 unbonding, found = keeper.GetUnbondingDelegation(ctx, del, valA)707 require.True(t, found)708 require.Equal(t, int64(2), unbonding.Balance.Amount.Int64())709 // redelegation should be unchanged710 redelegation, found = keeper.GetRedelegation(ctx, del, valA, valB)711 require.True(t, found)712 require.Equal(t, int64(3), redelegation.Balance.Amount.Int64())713 // destination delegation should be unchanged714 delegation, found = keeper.GetDelegation(ctx, del, valB)715 require.True(t, found)716 require.Equal(t, sdk.NewRat(3), delegation.Shares)717 // validator power should have been reduced to zero718 // ergo validator should have been removed from the store719 _, found = keeper.GetValidator(ctx, valA)720 require.False(t, found)721}...

Full Screen

Full Screen

solver_test.go

Source:solver_test.go Github

copy

Full Screen

...7func TestGetRowHas(t *testing.T) {8 assert := assert.New(t)9 testBoard := board.Board{Spots: [][]uint8{{0, 0, 1, 2}, {0, 0, 3, 4}, {0, 1, 2, 3}, {1, 2, 3, 4}}}10 got := getRowHas(testBoard, 0)11 assert.Equal([]bool{true, true, false, false}, got, "getRowHas did not work.")12}13func TestGetColHas(t *testing.T) {14 assert := assert.New(t)15 testBoard := board.Board{Spots: [][]uint8{{0, 0, 1, 2}, {0, 0, 3, 4}, {0, 1, 2, 3}, {1, 2, 0, 4}}}16 got := getColHas(testBoard, 0)17 assert.Equal([]bool{true, false, false, false}, got, "getColHas did not work.")18}19func TestGetSqrHas(t *testing.T) {20 assert := assert.New(t)21 testBoard := board.Board{Spots: [][]uint8{{0, 1}, {2, 1}}}22 got := getSqrHas(testBoard, 0, 0)23 assert.Equal([]bool{false, false}, got, "getSqrHas did not work for 2x2.")24 testBoard = board.Board{Spots: [][]uint8{{0, 0, 1, 2}, {0, 0, 3, 4}, {0, 1, 2, 3}, {1, 2, 3, 4}}}25 got = getSqrHas(testBoard, 0, 3)26 assert.Equal([]bool{true, true, true, true}, got, "getSqrHas did not work.")27}28func TestSpotPossible(t *testing.T) {29 assert := assert.New(t)30 testBoard := board.Board{Spots: [][]uint8{{0, 0, 1, 2}, {0, 0, 3, 4}, {0, 1, 2, 3}, {1, 2, 0, 0}}}31 got := spotPossible(3, 2, testBoard)32 assert.Equal([]bool{false, false, false, true}, got, "spotPossible did not work.")33}34func TestSinglePossible(t *testing.T) {35 assert := assert.New(t)36 testBoard := board.Board{Spots: [][]uint8{{0, 0, 1, 2}, {0, 0, 3, 4}, {0, 1, 2, 3}, {1, 2, 0, 0}}}37 gotBool, gotValue := singlePossible(3, 2, testBoard)38 assert.Equal(true, gotBool, "singlePossible should be true.")39 assert.Equal(uint8(4), gotValue, "singlePossible value should be 4.")40}41func TestSolveSinglePossible(t *testing.T) {42 assert := assert.New(t)43 testBoard := board.Board{Spots: [][]uint8{{0, 0, 1, 2}, {0, 0, 3, 4}, {0, 1, 2, 3}, {0, 2, 0, 0}}}44 gotBool, gotBoard := solveSinglePossible(testBoard)45 assert.Equal(true, gotBool, "solveSinglePossible should be true (on first run).")46 expectedBoard := board.Board{Spots: [][]uint8{{0, 0, 1, 2}, {0, 0, 3, 4}, {4, 1, 2, 3}, {3, 2, 4, 1}}}47 assert.Equal(expectedBoard, gotBoard, "Board solved incorrectly.")48 gotBool, gotBoard = solveSinglePossible(gotBoard)49 assert.Equal(false, gotBool, "solveSinglePossible should be false (on second run).")50 expectedBoard = board.Board{Spots: [][]uint8{{0, 0, 1, 2}, {0, 0, 3, 4}, {4, 1, 2, 3}, {3, 2, 4, 1}}}51 assert.Equal(expectedBoard, gotBoard, "Board solved incorrectly.")52}53func TestOnlyPossibleInRow(t *testing.T) {54 assert := assert.New(t)55 testBoard := board.Board{Spots: [][]uint8{{0, 0, 0, 0}, {1, 2, 3, 4}, {2, 3, 4, 1}, {4, 1, 2, 3}}}56 gotBool, gotValue, gotColIndex := onlyPossibleInRow(0, testBoard)57 assert.Equal(true, gotBool, "onlyPossibleInRow should have returned isThere = true.")58 assert.Equal(1, int(gotValue), "onlyPossibleInRow should have returned value = 1")59 assert.Equal(2, gotColIndex, "onlyPossibleInRow should have returned colIndex = 0")60 testBoard = board.Board{Spots: [][]uint8{{0, 0, 0, 0}, {0, 2, 3, 4}, {2, 3, 4, 1}, {4, 1, 2, 3}}}61 gotBool, gotValue, gotColIndex = onlyPossibleInRow(0, testBoard)62 assert.Equal(true, gotBool, "onlyPossibleInRow should have returned isThere = true.")63 assert.Equal(2, int(gotValue), "onlyPossibleInRow should have returned value = 2")64 assert.Equal(3, gotColIndex, "onlyPossibleInRow should have returned colIndex = 0")65 testBoard = board.Board{Spots: [][]uint8{{0, 0, 0, 0}, {0, 2, 3, 4}, {0, 3, 4, 1}, {4, 1, 0, 3}}}66 gotBool, gotValue, gotColIndex = onlyPossibleInRow(0, testBoard)67 assert.Equal(true, gotBool, "onlyPossibleInRow should have returned isThere = true.")68 assert.Equal(3, int(gotValue), "onlyPossibleInRow should have returned value = 3")69 assert.Equal(0, gotColIndex, "onlyPossibleInRow should have returned colIndex = 0")70 testBoard = board.Board{Spots: [][]uint8{{0, 0, 0, 0}, {0, 2, 3, 4}, {0, 0, 4, 1}, {4, 1, 0, 3}}}71 gotBool, gotValue, gotColIndex = onlyPossibleInRow(0, testBoard)72 assert.Equal(true, gotBool, "onlyPossibleInRow should have returned isThere = true.")73 assert.Equal(4, int(gotValue), "onlyPossibleInRow should have returned value = 3")74 assert.Equal(1, gotColIndex, "onlyPossibleInRow should have returned colIndex = 0")75 testBoard = board.Board{Spots: [][]uint8{{0, 0, 0, 0}, {0, 2, 3, 4}, {0, 0, 4, 1}, {0, 1, 0, 3}}}76 gotBool, gotValue, gotColIndex = onlyPossibleInRow(0, testBoard)77 assert.Equal(false, gotBool, "onlyPossibleInRow should have returned isThere = true.")78 assert.Equal(0, int(gotValue), "onlyPossibleInRow should have returned value = 3")79 assert.Equal(0, gotColIndex, "onlyPossibleInRow should have returned colIndex = 0")80}81func TestOnlyPossibleInCol(t *testing.T) {82 assert := assert.New(t)83 testBoard := board.Board{Spots: [][]uint8{{0, 1, 2, 4}, {0, 2, 3, 1}, {0, 3, 4, 2}, {0, 4, 1, 3}}}84 gotBool, gotValue, gotColIndex := onlyPossibleInCol(0, testBoard)85 assert.Equal(true, gotBool, "onlyPossibleInCol should have returned isThere = true.")86 assert.Equal(1, int(gotValue), "onlyPossibleInCol should have returned value = 1")87 assert.Equal(2, gotColIndex, "onlyPossibleInCol should have returned colIndex = 0")88 testBoard = board.Board{Spots: [][]uint8{{0, 0, 2, 4}, {0, 2, 3, 1}, {0, 3, 4, 2}, {0, 4, 1, 3}}}89 gotBool, gotValue, gotColIndex = onlyPossibleInCol(0, testBoard)90 assert.Equal(true, gotBool, "onlyPossibleInCol should have returned isThere = true.")91 assert.Equal(2, int(gotValue), "onlyPossibleInCol should have returned value = 2")92 assert.Equal(3, gotColIndex, "onlyPossibleInCol should have returned colIndex = 0")93 testBoard = board.Board{Spots: [][]uint8{{0, 0, 0, 0}, {0, 2, 3, 4}, {0, 3, 4, 1}, {4, 1, 0, 3}}}94 gotBool, gotValue, gotColIndex = onlyPossibleInCol(0, testBoard)95 assert.Equal(true, gotBool, "onlyPossibleInCol should have returned isThere = true.")96 assert.Equal(3, int(gotValue), "onlyPossibleInCol should have returned value = 3")97 assert.Equal(0, gotColIndex, "onlyPossibleInCol should have returned colIndex = 0")98 testBoard = board.Board{Spots: [][]uint8{{0, 0, 0, 4}, {0, 2, 0, 1}, {0, 3, 4, 0}, {0, 4, 1, 3}}}99 gotBool, gotValue, gotColIndex = onlyPossibleInCol(0, testBoard)100 assert.Equal(true, gotBool, "onlyPossibleInCol should have returned isThere = true.")101 assert.Equal(4, int(gotValue), "onlyPossibleInCol should have returned value = 4")102 assert.Equal(1, gotColIndex, "onlyPossibleInCol should have returned colIndex = 1")103 testBoard = board.Board{Spots: [][]uint8{{0, 0, 0, 0}, {0, 2, 3, 4}, {0, 0, 4, 1}, {0, 1, 0, 3}}}104 gotBool, gotValue, gotColIndex = onlyPossibleInCol(0, testBoard)105 assert.Equal(false, gotBool, "onlyPossibleInCol should have returned isThere = false.")106 assert.Equal(0, int(gotValue), "onlyPossibleInCol should have returned value = 0")107 assert.Equal(0, gotColIndex, "onlyPossibleInCol should have returned colIndex = 0")108}109func TestOnlyPossibleInSqr(t *testing.T) {110 assert := assert.New(t)111 testBoard := board.Board{Spots: [][]uint8{{0, 0, 1, 0}, {0, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}}}112 gotBool, gotValue, gotRowIndex, gotColIndex := onlyPossibleInSqr(0, 0, testBoard)113 assert.Equal(true, gotBool, "onlyPossibleInSqr should have returned isThere = true.")114 assert.Equal(1, int(gotValue), "onlyPossibleInSqr should have returned value = 1")115 assert.Equal(1, gotRowIndex, "onlyPossibleInSqr should have returned rowIndex = 1")116 assert.Equal(0, gotColIndex, "onlyPossibleInSqr should have returned colIndex = 0")117 testBoard = board.Board{Spots: [][]uint8{{0, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}}}118 gotBool, gotValue, gotRowIndex, gotColIndex = onlyPossibleInSqr(0, 0, testBoard)119 assert.Equal(true, gotBool, "onlyPossibleInSqr should have returned isThere = true.")120 assert.Equal(1, int(gotValue), "onlyPossibleInSqr should have returned value = 1")121 assert.Equal(0, gotRowIndex, "onlyPossibleInSqr should have returned rowIndex = 0")122 assert.Equal(0, gotColIndex, "onlyPossibleInSqr should have returned colIndex = 0")123 testBoard = board.Board{Spots: [][]uint8{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}}}124 gotBool, gotValue, gotRowIndex, gotColIndex = onlyPossibleInSqr(0, 0, testBoard)125 assert.Equal(false, gotBool, "isThere")126 assert.Equal(0, int(gotValue), "value")127 assert.Equal(0, gotRowIndex, "rowIndex")128 assert.Equal(0, gotColIndex, "colIndex")129}130func Test(t *testing.T) {131 testBoard, _ := board.Build([]uint8{32, 32, 32, 50, 54, 32, 55, 32, 49, 10, 54, 56, 32, 32, 55, 32, 32, 57, 32, 10, 49, 57, 32, 32, 32, 52, 53, 32, 32, 10, 56, 50, 32, 49, 32, 32, 32, 52, 32, 10, 32, 32, 52, 54, 32, 50, 57, 32, 32, 10, 32, 53, 32, 32, 32, 51, 32, 50, 56, 10, 32, 32, 57, 51, 32, 32, 32, 55, 52, 10, 32, 52, 32, 32, 53, 32, 32, 51, 54, 10, 55, 32, 51, 32, 49, 56, 32, 32, 32, 10})132 Phase1(testBoard)133 Phase2(testBoard)134 solveOnlyPossibleRow(testBoard)135 solveOnlyPossibleCol(testBoard)136 // var tests = []struct {137 // value uint8138 // want int139 // }{140 // {1, 1},141 // {2, 2},142 // }...

Full Screen

Full Screen

cache_current_staker_chain_state_test.go

Source:cache_current_staker_chain_state_test.go Github

copy

Full Screen

...48 // Apply the on-chain validator set to [vdrs]49 vdrs, err := cs.ValidatorSet(constants.PrimaryNetworkID)50 assert.NoError(t, err)51 // Validate that the state was applied and the old state was cleared52 assert.EqualValues(t, 3, vdrs.Len())53 assert.EqualValues(t, node0Weight+node1Weight+node2Weight, vdrs.Weight())54 gotNode0Weight, exists := vdrs.GetWeight(nodeID0)55 assert.True(t, exists)56 assert.EqualValues(t, node0Weight, gotNode0Weight)57 gotNode1Weight, exists := vdrs.GetWeight(nodeID1)58 assert.True(t, exists)59 assert.EqualValues(t, node1Weight, gotNode1Weight)60 gotNode2Weight, exists := vdrs.GetWeight(nodeID2)61 assert.True(t, exists)62 assert.EqualValues(t, node2Weight, gotNode2Weight)63 _, exists = vdrs.GetWeight(nodeID3)64 assert.False(t, exists)65 }66 {67 // Apply the on-chain validator set again68 vdrs, err := cs.ValidatorSet(constants.PrimaryNetworkID)69 assert.NoError(t, err)70 // The state should be the same71 assert.EqualValues(t, 3, vdrs.Len())72 assert.EqualValues(t, node0Weight+node1Weight+node2Weight, vdrs.Weight())73 gotNode0Weight, exists := vdrs.GetWeight(nodeID0)74 assert.True(t, exists)75 assert.EqualValues(t, node0Weight, gotNode0Weight)76 gotNode1Weight, exists := vdrs.GetWeight(nodeID1)77 assert.True(t, exists)78 assert.EqualValues(t, node1Weight, gotNode1Weight)79 gotNode2Weight, exists := vdrs.GetWeight(nodeID2)80 assert.True(t, exists)81 assert.EqualValues(t, node2Weight, gotNode2Weight)82 }83}84func TestSubnetValidatorSet(t *testing.T) {85 subnetID := ids.GenerateTestID()86 // Initialize the chain state87 nodeID0 := ids.GenerateTestShortID()88 node0Weight := uint64(1)89 vdr0 := &currentValidatorImpl{90 validatorImpl: validatorImpl{91 subnets: map[ids.ID]*UnsignedAddSubnetValidatorTx{92 subnetID: {93 Validator: SubnetValidator{94 Validator: Validator{95 Wght: node0Weight,96 },97 },98 },99 },100 },101 }102 nodeID1 := ids.GenerateTestShortID()103 node1Weight := uint64(2)104 vdr1 := &currentValidatorImpl{105 validatorImpl: validatorImpl{106 subnets: map[ids.ID]*UnsignedAddSubnetValidatorTx{107 subnetID: {108 Validator: SubnetValidator{109 Validator: Validator{110 Wght: node1Weight,111 },112 },113 },114 },115 },116 }117 nodeID2 := ids.GenerateTestShortID()118 node2Weight := uint64(2)119 vdr2 := &currentValidatorImpl{120 validatorImpl: validatorImpl{121 subnets: map[ids.ID]*UnsignedAddSubnetValidatorTx{122 subnetID: {123 Validator: SubnetValidator{124 Validator: Validator{125 Wght: node2Weight,126 },127 },128 },129 },130 },131 }132 cs := &currentStakerChainStateImpl{133 validatorsByNodeID: map[ids.ShortID]*currentValidatorImpl{134 nodeID0: vdr0,135 nodeID1: vdr1,136 nodeID2: vdr2,137 },138 }139 nodeID3 := ids.GenerateTestShortID()140 {141 // Apply the on-chain validator set to [vdrs]142 vdrs, err := cs.ValidatorSet(subnetID)143 assert.NoError(t, err)144 // Validate that the state was applied and the old state was cleared145 assert.EqualValues(t, 3, vdrs.Len())146 assert.EqualValues(t, node0Weight+node1Weight+node2Weight, vdrs.Weight())147 gotNode0Weight, exists := vdrs.GetWeight(nodeID0)148 assert.True(t, exists)149 assert.EqualValues(t, node0Weight, gotNode0Weight)150 gotNode1Weight, exists := vdrs.GetWeight(nodeID1)151 assert.True(t, exists)152 assert.EqualValues(t, node1Weight, gotNode1Weight)153 gotNode2Weight, exists := vdrs.GetWeight(nodeID2)154 assert.True(t, exists)155 assert.EqualValues(t, node2Weight, gotNode2Weight)156 _, exists = vdrs.GetWeight(nodeID3)157 assert.False(t, exists)158 }159 {160 // Apply the on-chain validator set again161 vdrs, err := cs.ValidatorSet(subnetID)162 assert.NoError(t, err)163 // The state should be the same164 assert.EqualValues(t, 3, vdrs.Len())165 assert.EqualValues(t, node0Weight+node1Weight+node2Weight, vdrs.Weight())166 gotNode0Weight, exists := vdrs.GetWeight(nodeID0)167 assert.True(t, exists)168 assert.EqualValues(t, node0Weight, gotNode0Weight)169 gotNode1Weight, exists := vdrs.GetWeight(nodeID1)170 assert.True(t, exists)171 assert.EqualValues(t, node1Weight, gotNode1Weight)172 gotNode2Weight, exists := vdrs.GetWeight(nodeID2)173 assert.True(t, exists)174 assert.EqualValues(t, node2Weight, gotNode2Weight)175 }176}...

Full Screen

Full Screen

Equal

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 a := []int{1, 2, 3}4 b := []int{1, 2, 3}5 fmt.Println(cmp.Equal(a, b))6}

Full Screen

Full Screen

Equal

Using AI Code Generation

copy

Full Screen

1import (2type person struct {3}4func main() {5 p1 := person{"Raj", 25}6 p2 := person{"Raj", 25}7 fmt.Println(cmp.Equal(p1, p2))8}

Full Screen

Full Screen

Equal

Using AI Code Generation

copy

Full Screen

1import(2ype Emplyee struct {3}4fun main() {5e1 := Employee{Id: 1, Name: "Jhn"}6e2 := Eloyee{Id: 1, Nme: "John"}7if cmp.Equal(e1, e2) {8fmt.Println("e1 and e2 ae equal")9} els{10fm.Println("e1 and e2 are not equal")11}12}

Full Screen

Full Screen

Equal

Using AI Code Generation

copy

Full Screen

1import (2type Employee struct {3}4func main() {5e1 := Employee{Id: 1, Name: "John"}6e2 := Employee{Id: 1, Name: "John"}7if cmp.Equal(e1, e2) {8fmt.Println("e1 and e2 are equal")9} else {10fmt.Println("e1 and e2 are not equal")11}12}

Full Screen

Full Screen

Equal

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 slice1 := []int{1, 2, 3}4 slice2 := []int{1, 2, 3}5 assert.Equal(t, slice1, slice2)6 fmt.Println("Equal")7}8import (9func main() {10 slice1 := []int{1, 2, 3}11 slice2 := []int{1, 2, 3}12 assert.DeepEqual(t, slice1, slice2)13 fmt.Println("DeepEqual")14}15import (16func main() {17 slice1 := []int{1, 2, 3}18 slice2 := []int{1, 2, 3}19 assert.DeepEqual(t, slice1, slice2)20 fmt.Println("DeepEqual")21}22import (23func main() {24 slice1 := []int{1, 2, 3}25 slice2 := []int{1, 2, 3}26 assert.DeepEqual(t, slice1, slice2)27 fmt.Println("DeepEqual")28}29import (

Full Screen

Full Screen

Equal

Using AI Code Generation

copy

Full Screen

1import (2type Employee struct {3}4func main() {5 e1 := Employee{6 }t(1, 2)7 fmt.Println(a.Equal(b))8 fmt.Println(a.Equal(c))9}

Full Screen

Full Screen

Equal

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var a1, a2, a3, a4, a5, a6, a7, a8 inerface{}4 fmt.Println(reflect.DeepEqualaa))5 fmt.Println(reflect.DeepEqual(a3, a4)6 e2 := Emplo(reflect.DeepEqualye5, a6))7 fmtePrintln(reflect.DeepEqual(a7, a8))8}

Full Screen

Full Screen

Equal

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 type Employee struct {4 }5 emp1 := Employee{Id: 1, Name: "John"}6 emp2 := Employee{Id: 1, Name: "John"}7 if cmp.Equal(emp1, emp2) {8 fmt.Println("Equal"9 } else {10 fmt.Println("Not Equal"11 }12 }13 fmt.Println(cmp.Equal(e1, e2))14}

Full Screen

Full Screen

Equal

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 slice1 := []int{1, 2, 3}4 slice2 := []int{1, 2, 3}5 assert.Equal(t, slice1, slice2)6 fmt.Println("EEqual(c))7}

Full Screen

Full Screen

Equal

Using AI Code Generation

copy

Full Screen

1import )2fun main() {3 a = got.NewGot(1,2)4 b = got.NewGot(1,2)5 fmt.Println(a.Equal(b6}7import (8func main() {9 slice1 := []int{1, 2, 3}10 slice2 := []int{1, 2, 3}11 assert.DeepEqual(t, slice1, slice2)12 fmt.Println("DeepEqual")13}14import (15func main() {16 slice1 := []int{1, 2, 3}17 slice2 := []int{1, 2, 3}18 assert.DeepEqual(t, slice1, slice2)19 fmt.Println("DeepEqual")20}21import (22func main() {23 slice1 := []int{1, 2, 3}24 slice2 := []int{1, 2, 3}25 assert.DeepEqual(t, slice1, slice2)26 fmt.Println("DeepEqual")27}28import (

Full Screen

Full Screen

Equal

Using AI Code Generation

copy

Full Screen

1import (2type Employee struct {3}4func main() {5 e1 := Employee{6 }7 e2 := Employee{8 }9 fmt.Println(cmp.Equal(e1, e2))10}

Full Screen

Full Screen

Equal

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 a = got.NewGot(1, 2)4 b = got.NewGot(2, 1)5 c = got.NewGot(1, 2)6 fmt.Println(a.Equal(b))7 fmt.Println(a.Equal(c))8}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful