|
| 1 | +import { BigNumberInBase } from '@injectivelabs/utils' |
| 2 | +import MsgTransferDelegation from './MsgTransferDelegation.js' |
| 3 | +import snakecaseKeys from 'snakecase-keys' |
| 4 | +import { mockFactory, prepareEip712 } from '@injectivelabs/utils/test-utils' |
| 5 | +import { |
| 6 | + getEip712TypedData, |
| 7 | + getEip712TypedDataV2, |
| 8 | +} from '../../../tx/eip712/eip712.js' |
| 9 | +import { IndexerGrpcWeb3GwApi } from './../../../../client/indexer/grpc/IndexerGrpcWeb3GwApi.js' |
| 10 | +import { EIP712Version } from '@injectivelabs/ts-types' |
| 11 | + |
| 12 | +const params: MsgTransferDelegation['params'] = { |
| 13 | + validatorAddress: mockFactory.validatorAddress, |
| 14 | + injectiveAddress: mockFactory.injectiveAddress, |
| 15 | + receiverAddress: mockFactory.injectiveAddress2, |
| 16 | + amount: { |
| 17 | + amount: new BigNumberInBase(1).toFixed(), |
| 18 | + denom: 'inj', |
| 19 | + }, |
| 20 | +} |
| 21 | + |
| 22 | +const protoType = '/cosmos.staking.v1beta1.MsgTransferDelegation' |
| 23 | +const protoTypeAmino = 'cosmos-sdk/MsgTransferDelegation' |
| 24 | +const protoParams = { |
| 25 | + validatorAddress: params.validatorAddress, |
| 26 | + delegatorAddress: params.injectiveAddress, |
| 27 | + receiverAddress: params.receiverAddress, |
| 28 | + amount: params.amount, |
| 29 | +} |
| 30 | +const protoParamsAmino = snakecaseKeys(protoParams) |
| 31 | +const message = MsgTransferDelegation.fromJSON(params) |
| 32 | + |
| 33 | +describe('MsgTransferDelegation', () => { |
| 34 | + it('generates proper proto', () => { |
| 35 | + const proto = message.toProto() |
| 36 | + |
| 37 | + expect(proto).toStrictEqual(protoParams) |
| 38 | + }) |
| 39 | + |
| 40 | + it('generates proper data', () => { |
| 41 | + const data = message.toData() |
| 42 | + |
| 43 | + expect(data).toStrictEqual({ |
| 44 | + '@type': protoType, |
| 45 | + ...protoParams, |
| 46 | + }) |
| 47 | + }) |
| 48 | + |
| 49 | + it('generates proper amino', () => { |
| 50 | + const amino = message.toAmino() |
| 51 | + |
| 52 | + expect(amino).toStrictEqual({ |
| 53 | + type: protoTypeAmino, |
| 54 | + value: protoParamsAmino, |
| 55 | + }) |
| 56 | + }) |
| 57 | + |
| 58 | + it('generates proper web3Gw', () => { |
| 59 | + const web3 = message.toWeb3Gw() |
| 60 | + |
| 61 | + expect(web3).toStrictEqual({ |
| 62 | + '@type': protoType, |
| 63 | + ...protoParamsAmino, |
| 64 | + }) |
| 65 | + }) |
| 66 | + |
| 67 | + describe('generates proper EIP712 compared to the Web3Gw (chain)', () => { |
| 68 | + const { endpoints, eip712Args, prepareEip712Request } = prepareEip712({ |
| 69 | + messages: message, |
| 70 | + }) |
| 71 | + |
| 72 | + it('EIP712 v1', async () => { |
| 73 | + const eip712TypedData = getEip712TypedData(eip712Args) |
| 74 | + |
| 75 | + const txResponse = await new IndexerGrpcWeb3GwApi( |
| 76 | + endpoints.indexer, |
| 77 | + ).prepareEip712Request({ |
| 78 | + ...prepareEip712Request, |
| 79 | + eip712Version: EIP712Version.V1, |
| 80 | + }) |
| 81 | + |
| 82 | + expect(eip712TypedData).toStrictEqual(JSON.parse(txResponse.data)) |
| 83 | + }) |
| 84 | + |
| 85 | + it('EIP712 v2', async () => { |
| 86 | + const eip712TypedData = getEip712TypedDataV2(eip712Args) |
| 87 | + |
| 88 | + const txResponse = await new IndexerGrpcWeb3GwApi( |
| 89 | + endpoints.indexer, |
| 90 | + ).prepareEip712Request({ |
| 91 | + ...prepareEip712Request, |
| 92 | + eip712Version: EIP712Version.V2, |
| 93 | + }) |
| 94 | + |
| 95 | + expect(eip712TypedData).toStrictEqual(JSON.parse(txResponse.data)) |
| 96 | + }) |
| 97 | + }) |
| 98 | +}) |
0 commit comments