import { expect } from 'chai'; import { TypedDataField } from 'ethers'; import { getWithdrawReqValue, withdrawReqTypes, getAuctionLendReqValue, getAuctionBorrowReqValue, getCancelOrderReqValue, getSecondLimitOrderReqValue, getSecondMarketOrderReqValue, getRedeemReqValue, auctionBorrowReqTypes, auctionLendReqTypes, cancelOrderReqTypes, redeemReqTypes, secondLimitOrderReqTypes, secondMarketOrderReqTypes, } from '../src'; import { typeDataTestCaseList } from './data/typedData.testcase'; describe(`signTypedData test`, function () { it('getWithdrawReqValue', function () { const { input, expectTypeDataValue } = typeDataTestCaseList['getWithdrawReqValue']; const inputTypeDataValue = getWithdrawReqValue(input); expectEIP712TypeDataMatchField(withdrawReqTypes, inputTypeDataValue, expectTypeDataValue); }); it('getAuctionLendReqValue', function () { const { input, expectTypeDataValue } = typeDataTestCaseList['getAuctionLendReqValue']; const inputTypeDataValue = getAuctionLendReqValue(input); expectEIP712TypeDataMatchField(auctionLendReqTypes, inputTypeDataValue, expectTypeDataValue); }); it('getAuctionBorrowReqValue', function () { const { input, expectTypeDataValue } = typeDataTestCaseList['getAuctionBorrowReqValue']; const inputTypeDataValue = getAuctionBorrowReqValue(input); expectEIP712TypeDataMatchField(auctionBorrowReqTypes, inputTypeDataValue, expectTypeDataValue); }); it('getCancelOrderReqValue', function () { const { input, expectTypeDataValue } = typeDataTestCaseList['getCancelOrderReqValue']; const inputTypeDataValue = getCancelOrderReqValue(input); expectEIP712TypeDataMatchField(cancelOrderReqTypes, inputTypeDataValue, expectTypeDataValue); }); it('getSecondLimitOrderReqValue', function () { const { input, expectTypeDataValue } = typeDataTestCaseList['getSecondLimitOrderReqValue']; const inputTypeDataValue = getSecondLimitOrderReqValue(input); expectEIP712TypeDataMatchField(secondLimitOrderReqTypes, inputTypeDataValue, expectTypeDataValue); }); it('getSecondMarketOrderReqValue', function () { const { input, expectTypeDataValue } = typeDataTestCaseList['getSecondMarketOrderReqValue']; const inputTypeDataValue = getSecondMarketOrderReqValue(input); expectEIP712TypeDataMatchField(secondMarketOrderReqTypes, inputTypeDataValue, expectTypeDataValue); }); it('getRedeemReqValue', function () { const { input, expectTypeDataValue } = typeDataTestCaseList['getRedeemReqValue']; const inputTypeDataValue = getRedeemReqValue(input); expectEIP712TypeDataMatchField(redeemReqTypes, inputTypeDataValue, expectTypeDataValue); }); }); function expectEIP712TypeDataMatchField(typedDataField: Record, inputTypeDataValue: any, expectTypeDataValue: any) { const mainField = typedDataField.Main; Object.values(mainField).forEach(({ name, type }) => { expect(typeof inputTypeDataValue[name]).equal(type); expect(inputTypeDataValue[name]).equal(expectTypeDataValue[name]); }); }