139 lines
6.1 KiB
JavaScript
139 lines
6.1 KiB
JavaScript
const MessageTest = artifacts.require('MessageTest.sol')
|
|
|
|
require('../setup')
|
|
const { expect } = require('chai')
|
|
|
|
contract('ArbitraryMessage.sol', async () => {
|
|
describe('unpackData', () => {
|
|
it('unpack dataType 0', async () => {
|
|
// given
|
|
const msgSender = '0x003667154bb32E42bb9e1E6532F19d187fa0082e'
|
|
const msgContractAddress = '0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955'
|
|
const msgId = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10'
|
|
const msgSrcChainId = '1122'
|
|
const msgDstChainId = '3344'
|
|
const msgGasLimit = '1535604485'
|
|
const msgDataType = '0'
|
|
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
|
// event message generated by
|
|
// requireToPassMessage(address _contract, bytes _data, uint256 _gas)
|
|
const message =
|
|
`${msgId}003667154bb32e42bb9e1e6532f19d187fa0082e` + // sender
|
|
'f4bef13f9f4f2b203faf0c3cbbaabe1afe056955' + // contractAddress
|
|
'5b877705' + // gasLimit
|
|
'02' + // source chain id length
|
|
'02' + // destination chain id length
|
|
'00' + // dataType
|
|
'1122' + // source chain id
|
|
'3344' + // destination chain id
|
|
'b1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03' // data
|
|
|
|
// when
|
|
const messageTest = await MessageTest.new()
|
|
const result = await messageTest.unpackData(message)
|
|
|
|
// then
|
|
const { messageId, chainIds, sender, executor, gasLimit, dataType, data } = result
|
|
expect(messageId).to.be.equal(msgId)
|
|
expect(chainIds[0].toString(16)).to.be.equal(msgSrcChainId)
|
|
expect(chainIds[1].toString(16)).to.be.equal(msgDstChainId)
|
|
expect(sender).to.be.equal(msgSender)
|
|
expect(executor).to.be.equal(msgContractAddress)
|
|
expect(gasLimit.toString()).to.be.equal(msgGasLimit)
|
|
expect(dataType).to.be.bignumber.equal(msgDataType)
|
|
expect(data).to.be.equal(msgData)
|
|
})
|
|
|
|
it('unpack dataType 0 with different chain ids', async () => {
|
|
// given
|
|
const msgSender = '0x003667154bb32E42bb9e1E6532F19d187fa0082e'
|
|
const msgContractAddress = '0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955'
|
|
const msgId = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10'
|
|
const chainIds = [
|
|
['01', '02'],
|
|
['0102', '03'],
|
|
['01', '0203'],
|
|
['010203', '040506'],
|
|
['1122334455667788112233445566778811223344556677881122334455667788', 'aa'],
|
|
[
|
|
'1122334455667788112233445566778811223344556677881122334455667788',
|
|
'1122334455667788112233445566778811223344556677881122334455667788'
|
|
],
|
|
['aa', '1122334455667788112233445566778811223344556677881122334455667788'],
|
|
['aabbccddeeff', '112233445566']
|
|
]
|
|
const msgGasLimit = '1535604485'
|
|
const msgDataType = '0'
|
|
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
|
// event message generated by
|
|
// requireToPassMessage(address _contract, bytes _data, uint256 _gas)
|
|
for (const [msgSrcChainId, msgDstChainId] of chainIds) {
|
|
const message =
|
|
`${msgId}003667154bb32e42bb9e1e6532f19d187fa0082e` + // sender
|
|
'f4bef13f9f4f2b203faf0c3cbbaabe1afe056955' + // contractAddress
|
|
'5b877705' + // gasLimit
|
|
`${(msgSrcChainId.length / 2).toString(16).padStart(2, '0')}` +
|
|
`${(msgDstChainId.length / 2).toString(16).padStart(2, '0')}` +
|
|
'00' + // dataType
|
|
`${msgSrcChainId}${msgDstChainId}b1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03` // data
|
|
|
|
// when
|
|
const messageTest = await MessageTest.new()
|
|
const result = await messageTest.unpackData(message)
|
|
|
|
// then
|
|
const { messageId, chainIds, sender, executor, gasLimit, dataType, data } = result
|
|
expect(messageId).to.be.equal(msgId)
|
|
expect(chainIds[0].toString(16).padStart(msgSrcChainId.length, '0')).to.be.equal(msgSrcChainId)
|
|
expect(chainIds[1].toString(16).padStart(msgDstChainId.length, '0')).to.be.equal(msgDstChainId)
|
|
expect(sender).to.be.equal(msgSender)
|
|
expect(executor).to.be.equal(msgContractAddress)
|
|
expect(gasLimit.toString()).to.be.equal(msgGasLimit)
|
|
expect(dataType).to.be.bignumber.equal(msgDataType)
|
|
expect(data).to.be.equal(msgData)
|
|
}
|
|
})
|
|
})
|
|
|
|
describe('unpackData with signatures parameters', () => {
|
|
it('unpack dataType 0', async () => {
|
|
// given
|
|
const msgSender = '0x003667154bb32E42bb9e1E6532F19d187fa0082e'
|
|
const msgContractAddress = '0xf4BEF13F9f4f2B203FAF0C3cBbaAbe1afE056955'
|
|
const msgId = '0xbdceda9d8c94838aca10c687da1411a07b1390e88239c0638cb9cc264219cc10'
|
|
const msgSrcChainId = '1122'
|
|
const msgDstChainId = '3344'
|
|
const msgGasLimit = '1535604485'
|
|
const msgDataType = '0'
|
|
const msgData = '0xb1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03'
|
|
// event message generated by
|
|
// requireToPassMessage(address _contract, bytes _data, uint256 _gas)
|
|
const message =
|
|
`${msgId}003667154bb32e42bb9e1e6532f19d187fa0082e` + // sender
|
|
'f4bef13f9f4f2b203faf0c3cbbaabe1afe056955' + // contractAddress
|
|
'5b877705' + // gasLimit
|
|
'02' + // source chain id length
|
|
'02' + // destination chain id length
|
|
'00' + // dataType
|
|
'1122' + // source chain id
|
|
'3344' + // destination chain id
|
|
'b1591967aed668a4b27645ff40c444892d91bf5951b382995d4d4f6ee3a2ce03' // data
|
|
|
|
// when
|
|
const messageTest = await MessageTest.new()
|
|
const result = await messageTest.unpackDataWithExtraParams(message, '0x')
|
|
|
|
// then
|
|
const { messageId, chainIds, sender, executor, gasLimit, dataType, data } = result
|
|
expect(messageId).to.be.equal(msgId)
|
|
expect(chainIds[0].toString(16)).to.be.equal(msgSrcChainId)
|
|
expect(chainIds[1].toString(16)).to.be.equal(msgDstChainId)
|
|
expect(sender).to.be.equal(msgSender)
|
|
expect(executor).to.be.equal(msgContractAddress)
|
|
expect(gasLimit.toString()).to.be.equal(msgGasLimit)
|
|
expect(dataType).to.be.bignumber.equal(msgDataType)
|
|
expect(data).to.be.equal(msgData)
|
|
})
|
|
})
|
|
})
|