Skip to content

Commit

Permalink
test: asset vault expected valid owner
Browse files Browse the repository at this point in the history
  • Loading branch information
geolffreym committed Jan 3, 2025
1 parent 7c632fc commit 40e8bfd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
1 change: 0 additions & 1 deletion contracts/assets/AssetOwnership.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ contract AssetOwnership is
/// @param assetId The unique identifier for the asset, which serves as the NFT ID.
function registerAsset(address to, uint256 assetId) external onlyApprovedAsset(to, assetId) {
_mint(to, assetId); // register asset as 721 token
// TODO bind account h
emit RegisteredAsset(to, assetId);
}

Expand Down
3 changes: 0 additions & 3 deletions contracts/assets/AssetVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ contract AssetVault is Initializable, UUPSUpgradeable, AccessControlledUpgradeab
/// @param assetId The identifier of the asset.
/// @param vault The vault type used to retrieve the asset (e.g., LIT, RSA, EC).
function getContent(uint256 assetId, T.VaultType vault) external view returns (bytes memory) {
// aca se deberia retornar directamente el vault utilizado en lugar de pasarlo?
// se podria almacenar la relacion del vault con el asset
// o retornar getVaultsForContent(assetId) return list of vaults
return _secured[assetId][vault];
}

Expand Down
3 changes: 3 additions & 0 deletions contracts/economics/Treasury.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ contract Treasury is
function collectFees(address[] calldata collectors, address currency) external restricted {
uint256 collectorsLen = collectors.length;
address pool = address(this); // fees pool is treasury
uint256 totalCollected = 0;

// For each collector, request the collected fees and add them to the treasury pool balance
for (uint256 i = 0; i < collectorsLen; i = i.uncheckedInc()) {
Expand All @@ -93,7 +94,9 @@ contract Treasury is
// register funds in treasury pool...
_sumLedgerEntry(pool, collected, currency);
emit FeesCollected(collectors[i], collected, currency);
totalCollected += collected;
}

}

/// @notice Function that should revert when msg.sender is not authorized to upgrade the contract.
Expand Down
1 change: 0 additions & 1 deletion test/assets/AssetReferendum.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import "forge-std/Test.sol";
import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";
import { IAssetRegistrable } from "contracts/core/interfaces/assets/IAssetRegistrable.sol";
import { IAssetVerifiable } from "contracts/core/interfaces/assets/IAssetVerifiable.sol";
import { INonceVerifiable } from "contracts/core/interfaces/base/INonceVerifiable.sol";
import { AssetReferendum } from "contracts/assets/AssetReferendum.sol";

import { BaseTest } from "test/BaseTest.t.sol";
Expand Down
39 changes: 33 additions & 6 deletions test/assets/AssetVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import "forge-std/Test.sol";
import { IAccessControl } from "@openzeppelin/contracts/access/IAccessControl.sol";
import { IAssetRegistrable } from "contracts/core/interfaces/assets/IAssetRegistrable.sol";
import { IAssetVerifiable } from "contracts/core/interfaces/assets/IAssetVerifiable.sol";
import { INonceVerifiable } from "contracts/core/interfaces/base/INonceVerifiable.sol";
import { IAssetOwnership } from "contracts/core/interfaces/assets/IAssetOwnership.sol";
import { IAssetVault } from "contracts/core/interfaces/assets/IAssetVault.sol";
import { AssetVault } from "contracts/assets/AssetVault.sol";

import { BaseTest } from "test/BaseTest.t.sol";
Expand All @@ -17,7 +18,7 @@ contract AssetVaultTest is BaseTest {
address ownership;
address referendum;

function setUp() public initialize {
function setUp() public initialize {
// setup the access manager to use during tests..
vault = deployAssetVault();
ownership = deployAssetOwnership();
Expand All @@ -26,26 +27,52 @@ contract AssetVaultTest is BaseTest {

function test_SetContent_ExpectedOwner() public {
vm.warp(1641070800);
uint256 assetId = 123456;
_registerAndApproveAsset(user, assetId);

// we could use the vault to store and share data seamlessly:
// this data is required by lit to decrypt the data:
// - lit accessControlConditions
// - lit dataToEncryptHash
// - the encrypted content stored elsewhere

// these are test purpose data no real data
// format: b64(conditions).b64(hash)
string memory b64 = "W3siY2hhaW4iOiJldGhlcmV1bSIsImNvbnRyYWN0QWR.NDU2Nzg5MGFiY2RQ1Njc4OTBhYmNk";
bytes memory data = abi.encode(b64);

vm.prank(user);
IAssetVault assetVault = IAssetVault(vault);
assetVault.setContent(assetId, T.VaultType.LIT, data);

vm.prank(admin);
bytes memory got = assetVault.getContent(assetId, T.VaultType.LIT);
string memory expected = abi.decode(got, (string));
assert(keccak256(abi.encodePacked(expected)) == keccak256(abi.encodePacked(b64)));
}

function test_SetContent_RevertIf_InvalidOwner() public {
vm.warp(1641070800);
vm.prank(user);

}

function test_SetContent_ValidVaultType() public {
vm.warp(1641070800);
vm.prank(user);

}

function test_Get_ValidStoredContent() public {
vm.warp(1641070800);
vm.prank(user);

}


function _registerAndApproveAsset(address to, uint256 assetId) private {
vm.prank(to);
IAssetRegistrable(referendum).submit(assetId);
vm.prank(governor);
IAssetRegistrable(referendum).approve(assetId);

vm.prank(to);
IAssetOwnership(ownership).registerAsset(to, assetId);
}
}

0 comments on commit 40e8bfd

Please sign in to comment.