1- import { AccountGroupType , AccountWalletType } from '@metamask/account-api' ;
1+ import {
2+ AccountGroupId ,
3+ AccountGroupType ,
4+ AccountWalletType ,
5+ } from '@metamask/account-api' ;
26import {
37 EthAccountType ,
48 SolAccountType ,
@@ -733,25 +737,37 @@ describe('selectAsset', () => {
733737 } ) ;
734738 } ) ;
735739
736- it ( 'scopes native and staked lookups to selected account' , ( ) => {
737- const stateWithSecondEvm = mockState ( ) ;
738- const account1Id =
739- stateWithSecondEvm . engine . backgroundState . AccountsController
740- . internalAccounts . selectedAccount ;
740+ it ( 'scopes native and staked lookups to selected account group' , ( ) => {
741+ const baseState = mockState ( ) ;
742+
743+ // Account 1 info (already exists in mockState)
744+ const account1Id = 'd7f11451-9d79-4df4-a012-afd253443639' ;
745+ const group1Id = 'entropy:01K1TJY9QPSCKNBSVGZNG510GJ/0' ;
741746
747+ // Create second account group with different EVM account
742748 const account2Id = '11111111-1111-1111-1111-111111111111' ;
743749 const account2Address = '0x1111111111111111111111111111111111111111' ;
744750 const account2AddressLowercased = account2Address . toLowerCase ( ) ;
751+ const group2Id = 'entropy:01K1TJY9QPSCKNBSVGZNG510GJ/1' ;
752+ const walletId = 'entropy:01K1TJY9QPSCKNBSVGZNG510GJ' ;
745753
746- const withSelectedAccount = (
754+ const withSelectedGroup = (
747755 state : RootState ,
756+ selectedGroup : AccountGroupId ,
748757 selectedAccount : string ,
749758 ) : RootState => ( {
750759 ...state ,
751760 engine : {
752761 ...state . engine ,
753762 backgroundState : {
754763 ...state . engine . backgroundState ,
764+ AccountTreeController : {
765+ ...state . engine . backgroundState . AccountTreeController ,
766+ accountTree : {
767+ ...state . engine . backgroundState . AccountTreeController . accountTree ,
768+ selectedAccountGroup : selectedGroup ,
769+ } ,
770+ } ,
755771 AccountsController : {
756772 ...state . engine . backgroundState . AccountsController ,
757773 internalAccounts : {
@@ -764,8 +780,8 @@ describe('selectAsset', () => {
764780 } ,
765781 } ) ;
766782
767- // Add second EVM internal account into the same selected account group
768- stateWithSecondEvm . engine . backgroundState . AccountsController . internalAccounts . accounts [
783+ // Add second EVM account to AccountsController
784+ baseState . engine . backgroundState . AccountsController . internalAccounts . accounts [
769785 account2Id
770786 ] = {
771787 id : account2Id ,
@@ -783,73 +799,75 @@ describe('selectAsset', () => {
783799 } ,
784800 } ;
785801
786- const groupId = 'entropy:01K1TJY9QPSCKNBSVGZNG510GJ/0' ;
787- const walletId = 'entropy:01K1TJY9QPSCKNBSVGZNG510GJ' ;
788- stateWithSecondEvm . engine . backgroundState . AccountTreeController . accountTree . wallets [
802+ // Create second account group with the second EVM account
803+ baseState . engine . backgroundState . AccountTreeController . accountTree . wallets [
789804 walletId
790- ] . groups [ groupId ] . accounts = [
791- ...stateWithSecondEvm . engine . backgroundState . AccountTreeController
792- . accountTree . wallets [ walletId ] . groups [ groupId ] . accounts ,
793- account2Id ,
794- ] ;
805+ ] . groups [ group2Id ] = {
806+ id : group2Id ,
807+ type : AccountGroupType . MultichainAccount ,
808+ accounts : [ account2Id ] ,
809+ metadata : {
810+ name : 'Account Group 2' ,
811+ pinned : false ,
812+ hidden : false ,
813+ entropy : {
814+ groupIndex : 1 ,
815+ } ,
816+ } ,
817+ } ;
795818
796- // Provide AccountTracker balances for second address on mainnet
797- stateWithSecondEvm . engine . backgroundState . AccountTrackerController . accountsByChainId [
819+ // Provide AccountTracker balances for second account on mainnet
820+ baseState . engine . backgroundState . AccountTrackerController . accountsByChainId [
798821 '0x1'
799822 ] [ account2AddressLowercased ] = {
800823 balance : '0x0DE0B6B3A7640000' , // 1 ETH
801824 stakedBalance : '0x1BC16D674EC80000' , // 2 ETH
802825 } ;
803826
804- // Provide empty token lists/balances for second address to keep asset building stable
805- stateWithSecondEvm . engine . backgroundState . TokensController . allTokens [ '0x1' ] [
827+ // Provide empty token lists/balances for second address
828+ baseState . engine . backgroundState . TokensController . allTokens [ '0x1' ] [
806829 account2AddressLowercased
807830 ] = [ ] ;
808- stateWithSecondEvm . engine . backgroundState . TokensController . allTokens [ '0xa' ] [
831+ baseState . engine . backgroundState . TokensController . allTokens [ '0xa' ] [
809832 account2AddressLowercased
810833 ] = [ ] ;
811834 (
812- stateWithSecondEvm . engine . backgroundState . TokenBalancesController
835+ baseState . engine . backgroundState . TokenBalancesController
813836 . tokenBalances as Record < string , unknown >
814837 ) [ account2AddressLowercased ] = { } ;
815838
816- // Sanity check: original account still resolves correctly
817- const stateForAccount1 = withSelectedAccount (
818- stateWithSecondEvm ,
819- account1Id ,
820- ) ;
839+ // Test Group 1: should return account 1 balances
840+ const stateForGroup1 = withSelectedGroup ( baseState , group1Id , account1Id ) ;
821841
822- const stakedForAccount1 = selectAsset ( stateForAccount1 , {
842+ const stakedForGroup1 = selectAsset ( stateForGroup1 , {
823843 address : '0x0000000000000000000000000000000000000000' ,
824844 chainId : '0x1' ,
825845 isStaked : true ,
826846 } ) ;
827- expect ( stakedForAccount1 ?. balance ) . toBe ( '100' ) ;
847+ expect ( stakedForGroup1 ?. balance ) . toBe ( '100' ) ;
848+ expect ( stakedForGroup1 ?. balanceFiat ) . toBe ( '$240,000.00' ) ;
828849
829- // Switch selected account → balances should follow
830- const stateForAccount2 = withSelectedAccount (
831- stateWithSecondEvm ,
832- account2Id ,
833- ) ;
850+ // Test Group 2: should return account 2 balances
851+ const stateForGroup2 = withSelectedGroup ( baseState , group2Id , account2Id ) ;
834852
835- const nativeForAccount2 = selectAsset ( stateForAccount2 , {
853+ const nativeForGroup2 = selectAsset ( stateForGroup2 , {
836854 address : '0x0000000000000000000000000000000000000000' ,
837855 chainId : '0x1' ,
838856 isStaked : false ,
839857 } ) ;
840- expect ( nativeForAccount2 ) . toMatchObject ( {
858+ expect ( nativeForGroup2 ) . toMatchObject ( {
841859 name : 'Ethereum' ,
842860 balance : '1' ,
843861 balanceFiat : '$2,400.00' ,
844862 isStaked : false ,
845863 } ) ;
846864
847- const stakedForAccount2 = selectAsset ( stateForAccount2 , {
865+ const stakedForGroup2 = selectAsset ( stateForGroup2 , {
848866 address : '0x0000000000000000000000000000000000000000' ,
849867 chainId : '0x1' ,
850868 isStaked : true ,
851869 } ) ;
852- expect ( stakedForAccount2 ) . toMatchObject ( {
870+ expect ( stakedForGroup2 ) . toMatchObject ( {
853871 name : 'Staked Ethereum' ,
854872 balance : '2' ,
855873 balanceFiat : '$4,800.00' ,
0 commit comments