|
| 1 | +import { createTxMsgDeposit, MessageMsgDepositParams } from './msgDeposit' |
| 2 | + |
| 3 | +describe('msgDeposit tests', () => { |
| 4 | + it('valid', async () => { |
| 5 | + const chain = { |
| 6 | + chainId: 9000, |
| 7 | + cosmosChainId: 'evmos_9000-1', |
| 8 | + } |
| 9 | + |
| 10 | + const sender = { |
| 11 | + accountAddress: 'ethm1tfegf50n5xl0hd5cxfzjca3ylsfpg0fned5gqm', |
| 12 | + sequence: 1, |
| 13 | + accountNumber: 9, |
| 14 | + pubkey: 'AgTw+4v0daIrxsNSW4FcQ+IoingPseFwHO1DnssyoOqZ', |
| 15 | + } |
| 16 | + |
| 17 | + const fee = { |
| 18 | + amount: '20', |
| 19 | + denom: 'aevmos', |
| 20 | + gas: '200000', |
| 21 | + } |
| 22 | + |
| 23 | + const memo = '' |
| 24 | + |
| 25 | + const params: MessageMsgDepositParams = { |
| 26 | + proposalId: 42, |
| 27 | + deposit: { |
| 28 | + amount: '1', |
| 29 | + denom: 'aevmos', |
| 30 | + }, |
| 31 | + } |
| 32 | + |
| 33 | + const msg = createTxMsgDeposit(chain, sender, fee, memo, params) |
| 34 | + expect( |
| 35 | + Buffer.from(msg.legacyAmino.body.serializeBinary()).toString('base64'), |
| 36 | + ).toBe( |
| 37 | + 'Cl4KHi9jb3Ntb3MuZ292LnYxYmV0YTEuTXNnRGVwb3NpdBI8CCoSK2V0aG0xdGZlZ2Y1MG41eGwwaGQ1Y3hmempjYTN5bHNmcGcwZm5lZDVncW0aCwoGYWV2bW9zEgEx', |
| 38 | + ) |
| 39 | + expect( |
| 40 | + Buffer.from(msg.legacyAmino.authInfo.serializeBinary()).toString( |
| 41 | + 'base64', |
| 42 | + ), |
| 43 | + ).toBe( |
| 44 | + 'ClkKTwooL2V0aGVybWludC5jcnlwdG8udjEuZXRoc2VjcDI1NmsxLlB1YktleRIjCiECBPD7i/R1oivGw1JbgVxD4iiKeA+x4XAc7UOeyzKg6pkSBAoCCH8YARISCgwKBmFldm1vcxICMjAQwJoM', |
| 45 | + ) |
| 46 | + expect(msg.legacyAmino.signBytes).toBe( |
| 47 | + 'rPuR5O7Omn7EdM790sDbISuhQB1GGZz3YIzq34HBh3k=', |
| 48 | + ) |
| 49 | + |
| 50 | + expect( |
| 51 | + Buffer.from(msg.signDirect.body.serializeBinary()).toString('base64'), |
| 52 | + ).toBe( |
| 53 | + 'Cl4KHi9jb3Ntb3MuZ292LnYxYmV0YTEuTXNnRGVwb3NpdBI8CCoSK2V0aG0xdGZlZ2Y1MG41eGwwaGQ1Y3hmempjYTN5bHNmcGcwZm5lZDVncW0aCwoGYWV2bW9zEgEx', |
| 54 | + ) |
| 55 | + expect( |
| 56 | + Buffer.from(msg.signDirect.authInfo.serializeBinary()).toString('base64'), |
| 57 | + ).toBe( |
| 58 | + 'ClkKTwooL2V0aGVybWludC5jcnlwdG8udjEuZXRoc2VjcDI1NmsxLlB1YktleRIjCiECBPD7i/R1oivGw1JbgVxD4iiKeA+x4XAc7UOeyzKg6pkSBAoCCAEYARISCgwKBmFldm1vcxICMjAQwJoM', |
| 59 | + ) |
| 60 | + expect(msg.signDirect.signBytes).toBe( |
| 61 | + '3BTa2GzN5hI2IiNsrOsbtxbNSRqIxgar49teQWcxIa0=', |
| 62 | + ) |
| 63 | + |
| 64 | + expect(msg.eipToSign).toStrictEqual({ |
| 65 | + domain: { |
| 66 | + chainId: 9000, |
| 67 | + name: 'Cosmos Web3', |
| 68 | + salt: '0', |
| 69 | + verifyingContract: 'cosmos', |
| 70 | + version: '1.0.0', |
| 71 | + }, |
| 72 | + message: { |
| 73 | + account_number: '9', |
| 74 | + chain_id: 'evmos_9000-1', |
| 75 | + fee: { |
| 76 | + amount: [{ amount: '20', denom: 'aevmos' }], |
| 77 | + feePayer: 'ethm1tfegf50n5xl0hd5cxfzjca3ylsfpg0fned5gqm', |
| 78 | + gas: '200000', |
| 79 | + }, |
| 80 | + memo: '', |
| 81 | + msgs: [ |
| 82 | + { |
| 83 | + type: 'cosmos-sdk/MsgDeposit', |
| 84 | + value: { |
| 85 | + proposal_id: 42, |
| 86 | + depositor: 'ethm1tfegf50n5xl0hd5cxfzjca3ylsfpg0fned5gqm', |
| 87 | + deposit: [{ amount: '1', denom: 'aevmos' }], |
| 88 | + }, |
| 89 | + }, |
| 90 | + ], |
| 91 | + sequence: '1', |
| 92 | + }, |
| 93 | + primaryType: 'Tx', |
| 94 | + types: { |
| 95 | + Coin: [ |
| 96 | + { name: 'denom', type: 'string' }, |
| 97 | + { name: 'amount', type: 'string' }, |
| 98 | + ], |
| 99 | + EIP712Domain: [ |
| 100 | + { name: 'name', type: 'string' }, |
| 101 | + { name: 'version', type: 'string' }, |
| 102 | + { name: 'chainId', type: 'uint256' }, |
| 103 | + { name: 'verifyingContract', type: 'string' }, |
| 104 | + { name: 'salt', type: 'string' }, |
| 105 | + ], |
| 106 | + Fee: [ |
| 107 | + { name: 'feePayer', type: 'string' }, |
| 108 | + { name: 'amount', type: 'Coin[]' }, |
| 109 | + { name: 'gas', type: 'string' }, |
| 110 | + ], |
| 111 | + Msg: [ |
| 112 | + { name: 'type', type: 'string' }, |
| 113 | + { name: 'value', type: 'MsgValue' }, |
| 114 | + ], |
| 115 | + MsgValue: [ |
| 116 | + { name: 'proposal_id', type: 'uint64' }, |
| 117 | + { name: 'depositor', type: 'string' }, |
| 118 | + { name: 'deposit', type: 'Coin[]' }, |
| 119 | + ], |
| 120 | + Tx: [ |
| 121 | + { name: 'account_number', type: 'string' }, |
| 122 | + { name: 'chain_id', type: 'string' }, |
| 123 | + { name: 'fee', type: 'Fee' }, |
| 124 | + { name: 'memo', type: 'string' }, |
| 125 | + { name: 'msgs', type: 'Msg[]' }, |
| 126 | + { name: 'sequence', type: 'string' }, |
| 127 | + ], |
| 128 | + }, |
| 129 | + }) |
| 130 | + }) |
| 131 | +}) |
0 commit comments