Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Refactor EIP712 ERC20 (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
0a1c authored Feb 24, 2023
1 parent 50c43f1 commit bee8050
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (transactions)[#125](https://github.com/evmos/evmosjs/pull/125) Refactor EIP-712 `Authz` package internally
- (transactions)[#126](https://github.com/evmos/evmosjs/pull/126) Refactor EIP-712 `Bank` package internally
- (transactions)[#127](https://github.com/evmos/evmosjs/pull/127) Refactor EIP-712 `Distribution` package internally
- (transactions)[#128](https://github.com/evmos/evmosjs/pull/128) Refactor EIP-712 `ERC-20` package internally
- (transactions)[#133](https://github.com/evmos/evmosjs/pull/133) Refactor EIP-712 `Vesting` package internally
3 changes: 1 addition & 2 deletions packages/eip712/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ export * from './encoding/utils'
export * from './messages/authz'
export * from './messages/bank'
export * from './messages/distribution'
export * from './messages/erc20'
export * from './messages/vesting'
export * from './messages/revenue/msgCancelRevenue'
export * from './messages/revenue/msgUpdateRevenue'
export * from './messages/revenue/msgRegisterRevenue'
export * from './messages/erc20/msgConvertCoin'
export * from './messages/erc20/msgConvertERC20'
export * from './messages/base'
export * from './messages/gov/msgVote'
export * from './messages/gov/msgSubmitProposal'
Expand Down
43 changes: 43 additions & 0 deletions packages/eip712/src/messages/erc20/convertCoin.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { MSG_CONVERT_COIN_TYPES, createMsgConvertCoin } from './convertCoin'
import TestUtils from '../../tests/utils'

describe('test MsgConvertCoin types and messages', () => {
it('creates types as expected', () => {
const expTypes = {
MsgValue: [
{ name: 'coin', type: 'TypeCoin' },
{ name: 'receiver', type: 'string' },
{ name: 'sender', type: 'string' },
],
TypeCoin: [
{ name: 'denom', type: 'string' },
{ name: 'amount', type: 'string' },
],
}

expect(MSG_CONVERT_COIN_TYPES).toStrictEqual(expTypes)
})

it('creates messages as expected', () => {
const { denom } = TestUtils
const amount = TestUtils.amount1
const senderBech32 = TestUtils.addr1
const receiverHex = TestUtils.addrHex1

const msg = createMsgConvertCoin(denom, amount, receiverHex, senderBech32)

const expMsg = {
type: 'evmos/MsgConvertCoin',
value: {
coin: {
denom,
amount,
},
receiver: receiverHex,
sender: senderBech32,
},
}

expect(msg).toStrictEqual(expMsg)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const MSG_CONVERT_COIN_TYPES = {
{ name: 'amount', type: 'string' },
],
}

export function createMsgConvertCoin(
denom: string,
amount: string,
Expand Down
43 changes: 43 additions & 0 deletions packages/eip712/src/messages/erc20/convertERC20.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { MSG_CONVERT_ERC20_TYPES, createMsgConvertERC20 } from './convertERC20'
import TestUtils from '../../tests/utils'

describe('test MsgConvertERC20 types and messages', () => {
it('creates types as expected', () => {
const expTypes = {
MsgValue: [
{ name: 'contract_address', type: 'string' },
{ name: 'amount', type: 'string' },
{ name: 'receiver', type: 'string' },
{ name: 'sender', type: 'string' },
],
}

expect(MSG_CONVERT_ERC20_TYPES).toStrictEqual(expTypes)
})

it('creates messages as expected', () => {
const contractAddress = TestUtils.addrHex1
const amount = TestUtils.amount1
const senderHex = TestUtils.addrHex2
const receiverBech32 = TestUtils.addr1

const msg = createMsgConvertERC20(
contractAddress,
amount,
receiverBech32,
senderHex,
)

const expMsg = {
type: 'evmos/MsgConvertERC20',
value: {
contract_address: contractAddress,
amount,
receiver: receiverBech32,
sender: senderHex,
},
}

expect(msg).toStrictEqual(expMsg)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const MSG_CONVERT_ERC20_TYPES = {
{ name: 'sender', type: 'string' },
],
}

export function createMsgConvertERC20(
contractAddress: string,
amount: string,
Expand Down
2 changes: 2 additions & 0 deletions packages/eip712/src/messages/erc20/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './convertCoin'
export * from './convertERC20'
4 changes: 4 additions & 0 deletions packages/eip712/src/tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class TestingClient {
public readonly addrVal2 =
'evmosvaloper1ex3wpda6mpczlgtcm2dsd60ltz39g5a7wqewls'

public readonly addrHex1 = '0xe2D61e49ff8a9d724CC54d338D8076F878aC6b71'

public readonly addrHex2 = '0xC1c85eB8278F783C5FE2103F1e4ac041B094160a'

public readonly chainId = 9001

public readonly memo = 'Transaction Memo'
Expand Down

0 comments on commit bee8050

Please sign in to comment.