/**
* Copyright 2017 ZuInnoTe (Jörn Franke) <zuinnote@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

package org.zuinnote.hadoop.ethereum.format.common;


import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class EthereumUtilEncodeTest {
   @Test
   public void encodeRLPElementLargeByteArray() {
	   String hexString="0A19B14A0000000000000000000000008F8221AFBB33998D8584A2B05749BA73C37A938A000000000000000000000000000000000000000000000028A857425466F80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004FEFA17B72400000000000000000000000000000000000000000000000000000000000000496606000000000000000000000000000000000000000000000000000000000B4594E6000000000000000000000000439F3E3AEB991155923B2E9D79B40169C38238C6000000000000000000000000000000000000000000000000000000000000001C6CAFDE39C9387CA142932617D966B4EEDA67ADE303604D3D7F57D796393324225DF009CCAA166300AC48C95013B8159F545CF11CC17B2BB23903FE1E5E02DD3D0000000000000000000000000000000000000000000000284041E810FF8A0000";
	   byte[] byteArray=EthereumUtil.convertHexStringToByteArray(hexString);
	   byte[] rlpEncode = EthereumUtil.encodeRLPElement(byteArray);
	   String rlpHexString = "B90164"+hexString;
	   assertEquals(rlpHexString,EthereumUtil.convertByteArrayToHexString(rlpEncode));
   }
   @Test
   public void encodeRLPElementLargeByteArray2()
   {
	   String hexString="6060604052341561000F57600080FD5B6040516060806105B08339810160405280805191906020018051919060200180519150505B600160A060020A038316151561004957600080FD5B60008054600160A060020A03808616600160A060020A0319928316179092556001805485841690831617905560028054928416929091169190911790555B5050505B6105168061009A6000396000F300606060405236156100675763FFFFFFFF60E060020A6000350416631072CBEA81146100A55780636C3B58E0146100C957806373FFD5B7146100F65780637822ED491461010E5780638DA5CB5B1461013D578063DC5F346B1461016C578063F444FDD814610199575B5B6000341161007557600080FD5B600154600160A060020A03163460405160006040518083038185876187965A03F19250505015156100A257FE5B5B005B34156100B057600080FD5B6100A2600160A060020A03600435166024356101C8565B005B34156100D457600080FD5B6100A2600160A060020A036004351660243560443560643560843561033A565B005B341561010157600080FD5B6100A26004356103AA565B005B341561011957600080FD5B61012161044D565B604051600160A060020A03909116815260200160405180910390F35B341561014857600080FD5B61012161045C565B604051600160A060020A03909116815260200160405180910390F35B341561017757600080FD5B6100A2600160A060020A036004351660243560443560643560843561046B565B005B34156101A457600080FD5B6101216104DB565B604051600160A060020A03909116815260200160405180910390F35B60025460009033600160A060020A03908116911614806101F6575060005433600160A060020A039081169116145B151561020157600080FD5B600160A060020A038316151561021357FE5B82600160A060020A03166370A082313060006040516020015260405160E060020A63FFFFFFFF8416028152600160A060020A039091166004820152602401602060405180830381600087803B151561026A57600080FD5B6102C65A03F1151561027B57600080FD5B50505060405180519150506000811180156102965750600082115B80156102A25750818110155B15156102AD57600080FD5B600154600160A060020A038085169163A9059CBB91168460006040516020015260405160E060020A63FFFFFFFF8516028152600160A060020A0390921660048301526024820152604401602060405180830381600087803B151561031057600080FD5B6102C65A03F1151561032157600080FD5B50505060405180519050151561033357FE5B5B5B505050565B60005433600160A060020A0390811691161461035557600080FD5B600160A060020A038516151561036A57600080FD5B80828486081461037957600080FD5B6001805473FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1916600160A060020A0387161790555B5B5050505050565B60025433600160A060020A03908116911614806103D5575060005433600160A060020A039081169116145B15156103E057600080FD5B600030600160A060020A0316311180156103FA5750600081115B801561041057508030600160A060020A03163110155B151561041B57600080FD5B600154600160A060020A03168160405160006040518083038185876187965A03F192505050151561044857FE5B5B5B50565B600154600160A060020A031681565B600054600160A060020A031681565B60005433600160A060020A0390811691161461048657600080FD5B600160A060020A038516151561049B57600080FD5B8082848608146104AA57600080FD5B6002805473FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1916600160A060020A0387161790555B5B5050505050565B600254600160A060020A0316815600A165627A7A72305820CF04E4D1DA97DCE96924EC4676A82FC1B7E1DF58CA22EC7328A5718A498BF8120029000000000000000000000000FE30E28B9DB06769D1D5F263905CDA31C4B2E0950000000000000000000000007B74C19124A9CA92C6141A2ED5F92130FC2791F20000000000000000000000007250ABCACDF1B5E19EC216619EA2614DC2FF6B7A";
	   byte[] byteArray=EthereumUtil.convertHexStringToByteArray(hexString);
	   byte[] rlpEncode = EthereumUtil.encodeRLPElement(byteArray);
	   String rlpHexString = "B90610"+hexString;
	   assertEquals(rlpHexString,EthereumUtil.convertByteArrayToHexString(rlpEncode));
   }
	
}
