mirror of
				https://github.com/0glabs/0g-chain.git
				synced 2025-11-04 10:37:26 +00:00 
			
		
		
		
	Implement GetBalance for extended balances which passes through to `x/bank` for non-extended denoms. This diverges from `x/evmutil` behavior which will panic on non-"akava" calls. Add bank / account keeper mocks for testing, with mockery config for [mockery package setup](https://vektra.github.io/mockery/latest/migrating_to_packages/)
		
			
				
	
	
		
			72 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			72 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package keeper_test
 | 
						|
 | 
						|
import (
 | 
						|
	"testing"
 | 
						|
 | 
						|
	sdkmath "cosmossdk.io/math"
 | 
						|
	"github.com/kava-labs/kava/x/precisebank/types"
 | 
						|
	"github.com/stretchr/testify/require"
 | 
						|
)
 | 
						|
 | 
						|
func TestGetSetRemainderAmount(t *testing.T) {
 | 
						|
	tk := NewMockedTestData(t)
 | 
						|
	ctx, k, storeKey := tk.ctx, tk.keeper, tk.storeKey
 | 
						|
 | 
						|
	// Set amount
 | 
						|
	k.SetRemainderAmount(ctx, sdkmath.NewInt(100))
 | 
						|
 | 
						|
	amt := k.GetRemainderAmount(ctx)
 | 
						|
	require.Equal(t, sdkmath.NewInt(100), amt)
 | 
						|
 | 
						|
	// Set zero balance
 | 
						|
	k.SetRemainderAmount(ctx, sdkmath.ZeroInt())
 | 
						|
 | 
						|
	amt = k.GetRemainderAmount(ctx)
 | 
						|
	require.Equal(t, sdkmath.ZeroInt(), amt)
 | 
						|
 | 
						|
	// Get directly from store to make sure it was actually deleted
 | 
						|
	store := ctx.KVStore(storeKey)
 | 
						|
	bz := store.Get(types.RemainderBalanceKey)
 | 
						|
	require.Nil(t, bz)
 | 
						|
}
 | 
						|
 | 
						|
func TestInvalidRemainderAmount(t *testing.T) {
 | 
						|
	tk := NewMockedTestData(t)
 | 
						|
	ctx, k := tk.ctx, tk.keeper
 | 
						|
 | 
						|
	// Set negative amount
 | 
						|
	require.PanicsWithError(t, "remainder amount is invalid: non-positive amount -1", func() {
 | 
						|
		k.SetRemainderAmount(ctx, sdkmath.NewInt(-1))
 | 
						|
	})
 | 
						|
 | 
						|
	// Set amount over max
 | 
						|
	require.PanicsWithError(t, "remainder amount is invalid: amount 1000000000000 exceeds max of 999999999999", func() {
 | 
						|
		k.SetRemainderAmount(ctx, types.ConversionFactor())
 | 
						|
	})
 | 
						|
}
 | 
						|
 | 
						|
func TestDeleteRemainderAmount(t *testing.T) {
 | 
						|
	tk := NewMockedTestData(t)
 | 
						|
	ctx, k, storeKey := tk.ctx, tk.keeper, tk.storeKey
 | 
						|
 | 
						|
	require.NotPanics(t, func() {
 | 
						|
		k.DeleteRemainderAmount(ctx)
 | 
						|
	})
 | 
						|
 | 
						|
	// Set amount
 | 
						|
	k.SetRemainderAmount(ctx, sdkmath.NewInt(100))
 | 
						|
 | 
						|
	amt := k.GetRemainderAmount(ctx)
 | 
						|
	require.Equal(t, sdkmath.NewInt(100), amt)
 | 
						|
 | 
						|
	// Delete amount
 | 
						|
	k.DeleteRemainderAmount(ctx)
 | 
						|
 | 
						|
	amt = k.GetRemainderAmount(ctx)
 | 
						|
	require.Equal(t, sdkmath.ZeroInt(), amt)
 | 
						|
 | 
						|
	store := ctx.KVStore(storeKey)
 | 
						|
	bz := store.Get(types.RemainderBalanceKey)
 | 
						|
	require.Nil(t, bz)
 | 
						|
}
 |