Skip to content

Commit

Permalink
test: checked that random changes with block time
Browse files Browse the repository at this point in the history
  • Loading branch information
onikonychev committed Jan 8, 2025
1 parent c6b71f6 commit d67b40f
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions x/evm/keeper/random_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
package keeper_test

import (
"time"

"github.com/NibiruChain/nibiru/v2/x/evm/embeds"
"github.com/NibiruChain/nibiru/v2/x/evm/evmtest"
)
Expand All @@ -14,9 +16,20 @@ func (s *Suite) TestRandom() {
randomContractAddr := deployResp.ContractAddr

// highjacked LoadERC20BigInt method as it perfectly fits the need of this test
resp, err := deps.EvmKeeper.LoadERC20BigInt(
random1, err := deps.EvmKeeper.LoadERC20BigInt(
deps.Ctx, embeds.SmartContract_TestRandom.ABI, randomContractAddr, "getRandom",
)
s.Require().NoError(err)
s.Require().NotNil(random1)
s.Require().NotZero(random1.Int64())

// Update block time to check that random changes
deps.Ctx = deps.Ctx.WithBlockTime(deps.Ctx.BlockTime().Add(1 * time.Second))
random2, err := deps.EvmKeeper.LoadERC20BigInt(
deps.Ctx, embeds.SmartContract_TestRandom.ABI, randomContractAddr, "getRandom",
)
s.Require().NoError(err)
s.Require().Greater(resp.Int64(), int64(0))
s.Require().NotNil(random1)
s.Require().NotZero(random2.Int64())
s.Require().NotEqual(random1, random2)
}

0 comments on commit d67b40f

Please sign in to comment.