-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c997858
commit 6c84c02
Showing
4 changed files
with
117 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...ages/confirmations/components/confirm/info/hooks/known-method-data-in-transaction.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { TransactionMeta } from '@metamask/transaction-controller'; | ||
import { | ||
CONTRACT_INTERACTION_SENDER_ADDRESS, | ||
genUnapprovedContractInteractionConfirmation, | ||
} from '../../../../../../../test/data/confirmations/contract-interaction'; | ||
import mockState from '../../../../../../../test/data/mock-state.json'; | ||
import { renderHookWithProvider } from '../../../../../../../test/lib/render-helpers'; | ||
import { useKnownMethodDataInTransaction } from './known-method-data-in-transaction'; | ||
|
||
describe('useKnownMethodDataInTransaction', () => { | ||
const depositHexData = '0xd0e30db0'; | ||
|
||
it('returns the method name and params', () => { | ||
const currentConfirmation = genUnapprovedContractInteractionConfirmation({ | ||
address: CONTRACT_INTERACTION_SENDER_ADDRESS, | ||
txData: depositHexData, | ||
}) as TransactionMeta; | ||
|
||
const { result } = renderHookWithProvider( | ||
() => useKnownMethodDataInTransaction(currentConfirmation), | ||
{ | ||
...mockState, | ||
metamask: { | ||
...mockState.metamask, | ||
use4ByteResolution: true, | ||
knownMethodData: { | ||
[depositHexData]: { name: 'Deposit', params: [] }, | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
expect(result.current.knownMethodData.name).toEqual('Deposit'); | ||
expect(result.current.knownMethodData.params).toEqual([]); | ||
}); | ||
|
||
it('returns no known method data if resolution is turned off', () => { | ||
const depositHexData = '0xd0e30db0'; | ||
|
||
const currentConfirmation = genUnapprovedContractInteractionConfirmation({ | ||
address: CONTRACT_INTERACTION_SENDER_ADDRESS, | ||
txData: depositHexData, | ||
}) as TransactionMeta; | ||
|
||
const { result } = renderHookWithProvider( | ||
() => useKnownMethodDataInTransaction(currentConfirmation), | ||
{ | ||
...mockState, | ||
metamask: { | ||
...mockState.metamask, | ||
use4ByteResolution: false, | ||
knownMethodData: { | ||
[depositHexData]: { name: 'Deposit', params: [] }, | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
expect(result.current.knownMethodData).toEqual({}); | ||
}); | ||
|
||
it("returns no method data if it's not known even if resolution is enabled", () => { | ||
const depositHexData = '0xd0e30db0'; | ||
|
||
const currentConfirmation = genUnapprovedContractInteractionConfirmation({ | ||
address: CONTRACT_INTERACTION_SENDER_ADDRESS, | ||
txData: depositHexData, | ||
}) as TransactionMeta; | ||
|
||
const { result } = renderHookWithProvider( | ||
() => useKnownMethodDataInTransaction(currentConfirmation), | ||
{ | ||
...mockState, | ||
metamask: { | ||
...mockState.metamask, | ||
use4ByteResolution: true, | ||
knownMethodData: {}, | ||
}, | ||
}, | ||
); | ||
|
||
expect(result.current.knownMethodData).toEqual({}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters