1- import { calculateCalldataCost , compressLZ , decompressLZ , compressZeros , decompressZeros , Bitstream } from "loopringV3.js" ;
1+ import {
2+ calculateCalldataCost ,
3+ compressLZ ,
4+ decompressLZ ,
5+ compressZeros ,
6+ decompressZeros ,
7+ Bitstream
8+ } from "loopringV3.js" ;
9+ import { CompressionSpeed } from "loopringV3.js" ;
210
311contract ( "Compression" , ( accounts : string [ ] ) => {
4- describe ( "LZ compression" , ( ) => {
12+ describe ( "LZ compression" , function ( ) {
13+ this . timeout ( 0 ) ;
14+
515 let lzDecompressor : any ;
616
717 const compressLZChecked = ( data : string ) => {
@@ -41,10 +51,37 @@ contract("Compression", (accounts: string[]) => {
4151 } ;
4252
4353 before ( async ( ) => {
44- const LzDecompressorContract = artifacts . require ( "LzDecompressorContract" ) ;
54+ const LzDecompressorContract = artifacts . require (
55+ "LzDecompressorContract"
56+ ) ;
4557 lzDecompressor = await LzDecompressorContract . new ( ) ;
4658 } ) ;
4759
60+ it . skip ( "Optimizer" , async ( ) => {
61+ const data =
62+ "0x0123456789987654301111111111111111111111111115548914444444444444121288412354425140000000000000" +
63+ "151156455787878787878787878787878454000000000000000000000000000000000000456487844878984567000000" +
64+ "151515151515151515151515151515151515151515151500000000000000000000000000000000000000000000000000" +
65+ "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
66+ "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
67+ "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" ;
68+
69+ let bestGas = 10000000 ;
70+ let bestN = 0 ;
71+ for ( let i = 20 ; i < 60 ; i ++ ) {
72+ const compressed = compressLZ ( data , i , CompressionSpeed . SLOW ) ;
73+ console . log ( compressed ) ;
74+ const tx = await lzDecompressor . benchmark ( compressed ) ;
75+ const gasUsed = tx . receipt . gasUsed ;
76+ if ( gasUsed < bestGas ) {
77+ bestGas = gasUsed ;
78+ bestN = i ;
79+ }
80+ console . log ( "" + i + ": " + gasUsed ) ;
81+ }
82+ console . log ( "Best - " + bestN + ": " + bestGas ) ;
83+ } ) ;
84+
4885 it ( "Test data" , async ( ) => {
4986 const data =
5087 "0x0123456789987654301111111111111111111111111115548914444444444444121288412354425140000000000000" +
@@ -150,7 +187,9 @@ contract("Compression", (accounts: string[]) => {
150187 } ;
151188
152189 before ( async ( ) => {
153- const ZeroDecompressorContract = artifacts . require ( "ZeroDecompressorContract" ) ;
190+ const ZeroDecompressorContract = artifacts . require (
191+ "ZeroDecompressorContract"
192+ ) ;
154193 zeroDecompressor = await ZeroDecompressorContract . new ( ) ;
155194 } ) ;
156195
@@ -165,6 +204,30 @@ contract("Compression", (accounts: string[]) => {
165204 await compressAndDecompressZerosChecked ( data ) ;
166205 } ) ;
167206
207+ it . skip ( "Optimizer" , async ( ) => {
208+ const data =
209+ "0x0123456789987654301111111111111111111111111115548914444444444444121288412354425140000000000000" +
210+ "151156455787878787878787878787878454000000000000000000000000000000000000456487844878984567000000" +
211+ "151515151515151515151515151515151515151515151500000000000000000000000000000000000000000000000000" +
212+ "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
213+ "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" +
214+ "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" ;
215+
216+ let bestGas = 10000000 ;
217+ let bestN = 0 ;
218+ for ( let i = 8 ; i < 100 ; i ++ ) {
219+ const compressed = compressZeros ( data , i ) ;
220+ const tx = await zeroDecompressor . benchmark ( compressed ) ;
221+ const gasUsed = tx . receipt . gasUsed ;
222+ if ( gasUsed < bestGas ) {
223+ bestGas = gasUsed ;
224+ bestN = i ;
225+ }
226+ console . log ( "" + i + ": " + gasUsed ) ;
227+ }
228+ console . log ( "Best - " + bestN + ": " + bestGas ) ;
229+ } ) ;
230+
168231 it ( "Random data" , async ( ) => {
169232 const numRounds = 8 ;
170233 const maxLength = 25 * 1000 ;
@@ -218,5 +281,4 @@ contract("Compression", (accounts: string[]) => {
218281 await compressAndDecompressZerosChecked ( bitstream . getData ( ) ) ;
219282 } ) ;
220283 } ) ;
221-
222284} ) ;
0 commit comments