@@ -3,29 +3,20 @@ pragma solidity ^0.8.24;
3
3
4
4
import {Test, console2} from "forge-std/Test.sol " ;
5
5
6
- library EncodingDecoding {
7
- function encodeLQTYAllocation (uint88 _lqty , uint32 _averageTimestamp ) public pure returns (uint224 ) {
8
- uint224 _value = (uint224 (_lqty) << 32 ) | _averageTimestamp;
9
- return _value;
10
- }
11
-
12
- function decodeLQTYAllocation (uint224 _value ) public pure returns (uint88 , uint32 ) {
13
- return (uint88 (_value >> 32 ), uint32 (_value));
14
- }
15
- }
6
+ import {EncodingDecodingLib} from "src/utils/EncodingDecodingLib.sol " ;
16
7
17
8
contract EncodingDecodingTest is Test {
18
9
// value -> encoding -> decoding -> value
19
10
function test_encoding_and_decoding_symmetrical (uint88 lqty , uint32 averageTimestamp ) public {
20
- uint224 encodedValue = EncodingDecoding .encodeLQTYAllocation (lqty, averageTimestamp);
21
- (uint88 decodedLqty , uint32 decodedAverageTimestamp ) = EncodingDecoding .decodeLQTYAllocation (encodedValue);
11
+ uint224 encodedValue = EncodingDecodingLib .encodeLQTYAllocation (lqty, averageTimestamp);
12
+ (uint88 decodedLqty , uint32 decodedAverageTimestamp ) = EncodingDecodingLib .decodeLQTYAllocation (encodedValue);
22
13
23
14
assertEq (lqty, decodedLqty);
24
15
assertEq (averageTimestamp, decodedAverageTimestamp);
25
16
26
17
// Redo
27
- uint224 reEncoded = EncodingDecoding .encodeLQTYAllocation (decodedLqty, decodedAverageTimestamp);
28
- (uint88 reDecodedLqty , uint32 reDecodedAverageTimestamp ) = EncodingDecoding .decodeLQTYAllocation (encodedValue);
18
+ uint224 reEncoded = EncodingDecodingLib .encodeLQTYAllocation (decodedLqty, decodedAverageTimestamp);
19
+ (uint88 reDecodedLqty , uint32 reDecodedAverageTimestamp ) = EncodingDecodingLib .decodeLQTYAllocation (encodedValue);
29
20
30
21
assertEq (reEncoded, encodedValue);
31
22
assertEq (reDecodedLqty, decodedLqty);
@@ -46,10 +37,10 @@ contract EncodingDecodingTest is Test {
46
37
// receive -> undo -> check -> redo -> compare
47
38
function _receive_undo_compare (uint224 encodedValue ) public {
48
39
/// These values fail because we could pass a value that is bigger than intended
49
- (uint88 decodedLqty , uint32 decodedAverageTimestamp ) = EncodingDecoding .decodeLQTYAllocation (encodedValue);
40
+ (uint88 decodedLqty , uint32 decodedAverageTimestamp ) = EncodingDecodingLib .decodeLQTYAllocation (encodedValue);
50
41
51
- uint224 encodedValue2 = EncodingDecoding .encodeLQTYAllocation (decodedLqty, decodedAverageTimestamp);
52
- (uint88 decodedLqty2 , uint32 decodedAverageTimestamp2 ) = EncodingDecoding .decodeLQTYAllocation (encodedValue2);
42
+ uint224 encodedValue2 = EncodingDecodingLib .encodeLQTYAllocation (decodedLqty, decodedAverageTimestamp);
43
+ (uint88 decodedLqty2 , uint32 decodedAverageTimestamp2 ) = EncodingDecodingLib .decodeLQTYAllocation (encodedValue2);
53
44
54
45
assertEq (encodedValue, encodedValue2, "encoded values not equal " );
55
46
assertEq (decodedLqty, decodedLqty2, "decoded lqty not equal " );
0 commit comments