66 lines
2.2 KiB
Solidity
66 lines
2.2 KiB
Solidity
// SPDX-License-Identifier: UNLICENSED
|
|
pragma solidity ^0.8.23;
|
|
|
|
import {Script, console2} from "forge-std/Script.sol";
|
|
import { DappIndexer} from "src/DappIndexer.sol";
|
|
import { CIDStorage } from "src/CIDStorage.sol";
|
|
|
|
contract DappIndexerScript is Script {
|
|
address public dappIndexerAddr;
|
|
address public CIDStorageAddr;
|
|
DappIndexer public dappIdxr;
|
|
string[] public dappsURI;
|
|
address public owner;
|
|
|
|
function setUp() public {
|
|
dappIndexerAddr = vm.envAddress("DAPPINDEXERADDRS");
|
|
dappsURI = vm.envString("dapps", ' ');
|
|
// Deployed contract must have Owner as ACC0)
|
|
owner = vm.envAddress("ACC0");
|
|
}
|
|
|
|
// run is the entry point
|
|
function run() public {
|
|
uint256 deployerPrivateKey = vm.envUint("PK0");
|
|
// startBroadcast and stopBraodcast will let us execute transactions anything between them
|
|
vm.startBroadcast(deployerPrivateKey);
|
|
// connect to the DappIndexer already deployed address
|
|
dappIdxr = DappIndexer(dappIndexerAddr);
|
|
|
|
console2.log("The Dapps Indexer contract address is: ", address(dappIdxr));
|
|
|
|
// Define a Dapp name
|
|
bytes32 dapp_name = bytes32("Dapp01");
|
|
|
|
// Define DappURI splited into two bytes32 CIDs
|
|
bytes32 CID1;
|
|
bytes32 CID2;
|
|
|
|
(CID1, CID2) = CIDStorage.stringToBytes32Pair(dappsURI[0]);
|
|
|
|
// Add Dapp
|
|
console2.log("-----Adding Dapp-----");
|
|
console2.log("Dapp Name is:");
|
|
console2.logBytes32(dapp_name);
|
|
console2.log("Bytes32 first:");
|
|
console2.logBytes32(CID1);
|
|
console2.log("Bytes32 second:");
|
|
console2.logBytes32(CID2);
|
|
console2.log(CIDStorage.bytes32PairToString(CID1, CID2));
|
|
dappIdxr.addDapp(dapp_name, DappIndexer.PackedCID(CID1, CID2));
|
|
|
|
// retrive Dapp
|
|
console2.log("-----retriving Dapp-----");
|
|
DappIndexer.PackedCID memory dapp1 = dappIdxr.getDapp(dapp_name);
|
|
console2.log("Bytes32 first:");
|
|
console2.logBytes32(dapp1.CID1);
|
|
console2.log("Bytes32 second:");
|
|
console2.logBytes32(dapp1.CID2);
|
|
|
|
// reconstruct the CID and verify
|
|
console2.log(CIDStorage.bytes32PairToString(dapp1.CID1, dapp1.CID2));
|
|
|
|
vm.stopBroadcast();
|
|
}
|
|
}
|