Skip to content

Commit

Permalink
build(besu-all-in-one): update besu image version
Browse files Browse the repository at this point in the history
* todo: check bungee-hermes besu-test-basic and ethereum-test-basic tests

 * added new satp contracts

Signed-off-by: eduv09 <eduardovasques10@tecnico.ulisboa.pt>
  • Loading branch information
eduv09 committed Jun 10, 2024
1 parent a2fe5e5 commit e714503
Show file tree
Hide file tree
Showing 9 changed files with 43,359 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
Servers,
} from "@hyperledger/cactus-common";
import "jest-extended";
import LockAssetContractJson from "../solidity/lock-asset-contract/LockAsset.json";

import SATPContract from "../../typescript/solidity/lock-asset-contract/SATPContract.json";
import SATPWrapperContract from "../../typescript/solidity/lock-asset-contract/SATPWrapperContract.json";
import { PluginRegistry } from "@hyperledger/cactus-core";
import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory";
import bodyParser from "body-parser";
Expand Down Expand Up @@ -44,7 +44,7 @@ import {
StrategyBesu,
} from "../../../main/typescript/strategy/strategy-besu";

const logLevel: LogLevelDesc = "INFO";
const logLevel: LogLevelDesc = "DEBUG";

let besuLedger: BesuTestLedger;
let contractName: string;
Expand Down Expand Up @@ -113,9 +113,10 @@ beforeAll(async () => {
backend: new Map([[keychainEntryKey, keychainEntryValue]]),
logLevel,
});
keychainPlugin.set(SATPContract.contractName, JSON.stringify(SATPContract));
keychainPlugin.set(
LockAssetContractJson.contractName,
JSON.stringify(LockAssetContractJson),
SATPWrapperContract.contractName,
JSON.stringify(SATPContract),
);

const pluginRegistry = new PluginRegistry({
Expand Down Expand Up @@ -175,28 +176,46 @@ beforeAll(async () => {

const deployOut = await connector.deployContract({
keychainId: keychainPlugin.getKeychainId(),
contractName: LockAssetContractJson.contractName,
contractAbi: LockAssetContractJson.abi,
constructorArgs: [],
contractName: SATPContract.contractName,
contractAbi: SATPContract.abi,
constructorArgs: [firstHighNetWorthAccount, BESU_ASSET_ID],
web3SigningCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
bytecode: LockAssetContractJson.bytecode,
gas: 1000000,
bytecode: SATPContract.bytecode,
gas: 6553352,
});
expect(deployOut).toBeTruthy();
expect(deployOut.transactionReceipt).toBeTruthy();
expect(deployOut.transactionReceipt.contractAddress).toBeTruthy();
log.info("Contract Deployed successfully");

const deployOut1 = await connector.deployContract({
keychainId: keychainPlugin.getKeychainId(),
contractName: SATPWrapperContract.contractName,
contractAbi: SATPWrapperContract.abi,
constructorArgs: [firstHighNetWorthAccount],
web3SigningCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
bytecode: SATPWrapperContract.bytecode,
gas: 553352,
});
expect(deployOut1).toBeTruthy();
expect(deployOut1.transactionReceipt).toBeTruthy();
expect(deployOut1.transactionReceipt.contractAddress).toBeTruthy();
log.info("Contract1 Deployed successfully");

const res = await connector.invokeContract({
contractName,
contractName: SATPContract.contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Send,
methodName: "createAsset",
params: [BESU_ASSET_ID, 19],
methodName: "mint",
params: [firstHighNetWorthAccount, 10000000],
signingCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
Expand All @@ -208,11 +227,16 @@ beforeAll(async () => {
expect(res.success).toBeTruthy();

const res3 = await connector.invokeContract({
contractName,
contractName: SATPWrapperContract.contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Call,
methodName: "getAsset",
params: [BESU_ASSET_ID],
methodName: "wrap",
params: [
deployOut.transactionReceipt.contractAddress,
"ERC20",
BESU_ASSET_ID,
firstHighNetWorthAccount,
],
signingCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
Expand Down Expand Up @@ -348,8 +372,8 @@ test("test creation of views for different timeframes and states", async () => {

afterAll(async () => {
await Servers.shutdown(besuServer);
await besuLedger.stop();
await besuLedger.destroy();
//await besuLedger.stop();
//await besuLedger.destroy();

await pruneDockerAllIfGithubAction({ logLevel })
.then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//////////////////////////////////

// Log settings
const testLogLevel: LogLevelDesc = "info";
const testLogLevel: LogLevelDesc = "DEBUG";

import "jest-extended";
import express from "express";
Expand Down Expand Up @@ -39,8 +39,9 @@ import {
GethTestLedger,
WHALE_ACCOUNT_ADDRESS,
} from "@hyperledger/cactus-test-geth-ledger";
import SATPContract from "../../typescript/solidity/lock-asset-contract/SATPContract.json";
import SATPWrappercontract from "../../typescript/solidity/lock-asset-contract/SATPWrapperContract.json";

import LockAssetContractJson from "../../typescript/solidity/lock-asset-contract/LockAsset.json";
import {
EthContractInvocationType,
PluginLedgerConnectorEthereum,
Expand Down Expand Up @@ -144,10 +145,8 @@ describe("Ethereum contract deploy and invoke using keychain", () => {
backend: new Map([[keychainEntryKey, keychainEntryValue]]),
logLevel: testLogLevel,
});
keychainPlugin.set(
LockAssetContractJson.contractName,
JSON.stringify(LockAssetContractJson),
);
keychainPlugin.set("SATPContract", JSON.stringify(SATPContract));
keychainPlugin.set("SATPWrapper", JSON.stringify(SATPWrappercontract));
connector = new PluginLedgerConnectorEthereum({
instanceId: uuidV4(),
rpcApiHttpHost,
Expand Down Expand Up @@ -178,35 +177,55 @@ describe("Ethereum contract deploy and invoke using keychain", () => {
expect(balance).toBeTruthy();
expect(balance.toString()).toBe(initTransferValue);

const deployOut = await apiClient.deployContract({
const deployOut = await connector.deployContract({
contract: {
contractName: LockAssetContractJson.contractName,
contractName: "SATPContract",
keychainId: keychainPlugin.getKeychainId(),
},
constructorArgs: [WHALE_ACCOUNT_ADDRESS, ETH_ASSET_NAME],
web3SigningCredential: {
ethAccount: WHALE_ACCOUNT_ADDRESS,
secret: "",
type: Web3SigningCredentialType.GethKeychainPassword,
},
});
log.info(deployOut.transactionReceipt);
expect(deployOut).toBeTruthy();
expect(deployOut.data).toBeTruthy();
expect(deployOut.data.transactionReceipt).toBeTruthy();
expect(deployOut.data.transactionReceipt.contractAddress).toBeTruthy();
expect(deployOut.transactionReceipt).toBeTruthy();
expect(deployOut.transactionReceipt.contractAddress).toBeTruthy();
log.info("contract deployed successfully");
expect(typeof contractAddress).toBe("string");
expect(contractAddress).toBeTruthy();

const deployOut1 = await apiClient.deployContract({
contract: {
contractName: "SATPWrapper",
keychainId: keychainPlugin.getKeychainId(),
},
web3SigningCredential: {
ethAccount: WHALE_ACCOUNT_ADDRESS,
secret: "",
type: Web3SigningCredentialType.GethKeychainPassword,
},
});
expect(deployOut1).toBeTruthy();
expect(deployOut1.data).toBeTruthy();
expect(deployOut1.data.transactionReceipt).toBeTruthy();
expect(deployOut1.data.transactionReceipt.contractAddress).toBeTruthy();
log.info("contract deployed successfully");
contractAddress = deployOut.data.transactionReceipt
contractAddress = deployOut1.data.transactionReceipt
.contractAddress as string;
expect(typeof contractAddress).toBe("string");
expect(contractAddress).toBeTruthy();

const invokeOut = await apiClient.invokeContractV1({
contract: {
contractName: LockAssetContractJson.contractName,
contractName: "SATPContract",
keychainId: keychainPlugin.getKeychainId(),
},
invocationType: EthContractInvocationType.Send,
methodName: "createAsset",
params: [ETH_ASSET_NAME, 10],
methodName: "mint",
params: [WHALE_ACCOUNT_ADDRESS, 1000000],
web3SigningCredential: {
ethAccount: WHALE_ACCOUNT_ADDRESS,
secret: "",
Expand All @@ -217,14 +236,33 @@ describe("Ethereum contract deploy and invoke using keychain", () => {
expect(invokeOut.data).toBeTruthy();
log.info("contract call successfull");

await apiClient.invokeContractV1({
contract: {
contractName: "SATPWrapper",
keychainId: keychainPlugin.getKeychainId(),
},
invocationType: EthContractInvocationType.Send,
methodName: "wrap",
params: [
deployOut.transactionReceipt.contractAddress,
"ERC20",
ETH_ASSET_NAME,
WHALE_ACCOUNT_ADDRESS,
],
web3SigningCredential: {
ethAccount: WHALE_ACCOUNT_ADDRESS,
secret: "",
type: Web3SigningCredentialType.GethKeychainPassword,
},
});
bungeeSigningCredential = {
ethAccount: WHALE_ACCOUNT_ADDRESS,
secret: "",
type: Web3SigningCredentialType.PrivateKeyHex,
};
bungeeKeychainId = keychainPlugin.getKeychainId();

bungeeContractAddress = deployOut.data.transactionReceipt
bungeeContractAddress = deployOut.transactionReceipt
.contractAddress as string;

pluginBungeeHermesOptions = {
Expand All @@ -248,7 +286,7 @@ describe("Ethereum contract deploy and invoke using keychain", () => {
bungee.addStrategy(strategy, new StrategyEthereum("INFO"));
const networkDetails: EthereumNetworkDetails = {
signingCredential: bungeeSigningCredential,
contractName: LockAssetContractJson.contractName,
contractName: "SATPWrapper",
connectorApiPath: apiHost,
keychainId: bungeeKeychainId,
contractAddress: bungeeContractAddress,
Expand Down Expand Up @@ -281,7 +319,7 @@ describe("Ethereum contract deploy and invoke using keychain", () => {
//expects nothing to limit time of 9999
expect(view1.view).toBeUndefined();
expect(view1.signature).toBeUndefined();

/*
//changing ETH_ASSET_NAME value
const lockAsset = await apiClient.invokeContractV1({
contract: {
Expand Down Expand Up @@ -355,6 +393,7 @@ describe("Ethereum contract deploy and invoke using keychain", () => {
snapshot.getStateBins()[0].getValue(),
);
}
*/
});
});

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: UNKNOWN

pragma solidity >=0.7.0;

/*
* Smart Contract Interface to define the methods needed by SATP Wrapper Contract.
*/

interface SATPContractInterface {
// mint creates new tokens with the given amount and assigns them to the owner.
function mint(address account, uint256 amount) external returns (bool);
// burn destroys the given amount of tokens from the owner.
function burn(address account, uint256 amount) external returns (bool);
// assign assigns the given amount of tokens from the owner to the target, without approval.
function assign(address from, address recipient, uint256 amount) external returns (bool);
// transfer transfers the given amount of tokens from the sender to the target, with approval needed.
function transfer(address from, address recipient, uint256 amount) external returns (bool);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.15;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "./ITraceableContract.sol";

import "hardhat/console.sol";
import "./satp-contract-interface.sol";


contract SATPContract is AccessControl, ERC20, ITraceableContract, SATPContractInterface {

bytes32 public constant BRIDGE_ROLE = keccak256("BRIDGE_ROLE");
bytes32 public constant OWNER_ROLE = keccak256("OWNER_ROLE");

string public id;

mapping (string => uint256) public balanceOf;

constructor(address _owner, string memory _id) ERC20("SATPToken", "SATP") {
_grantRole(OWNER_ROLE, _owner);
_grantRole(BRIDGE_ROLE, _owner);

id = _id;
string[] memory t = new string[](1);
t[0] = "atoa";
emit Changed(id, t);
}

function mint(address account, uint256 amount) external onlyRole(BRIDGE_ROLE) returns (bool success) {
console.log("Mint to: %s\n amount: %s", account, amount);
_mint(account, amount);
string[] memory t = new string[](1);
t[0] = "atoa";
emit Changed(id, t);
return true;
}

function burn(address account, uint256 amount) external onlyRole(BRIDGE_ROLE) returns (bool success) {
console.log("Burn from: %s\n amount: %s", account, amount);
_burn(account, amount);
string[] memory t = new string[](1);
t[0] = "atoa";
emit Changed(id, t);
return true;
}

function assign(address from, address recipient, uint256 amount) external onlyRole(BRIDGE_ROLE) returns (bool success) {
console.log("Assing from: %s\n to: %s \n amount: %s", from, recipient, amount);
require(from == _msgSender(), "The msgSender is not the owner");
_transfer(from, recipient, amount);
string[] memory t = new string[](1);
t[0] = "atoa";
emit Changed(id, t);
return true;
}

function transfer(address from, address recipient, uint256 amount) external onlyRole(BRIDGE_ROLE) returns (bool success) {
console.log("transfer from: %s\n to: %s \n amount: %s", from, recipient, amount);
transferFrom(from, recipient, amount);
string[] memory t = new string[](1);
t[0] = "atoa";
emit Changed(id, t);
return true;
}

function getAllAssetsIDs() external view returns (string[] memory) {
string[] memory myArray = new string[](1);
myArray[0] = id;
return myArray;
}

function getId() view public returns (string memory) {
return id;
}

function giveRole(address account) external onlyRole(OWNER_ROLE) returns (bool success) {
_grantRole(BRIDGE_ROLE, account);
string[] memory t = new string[](1);
t[0] = "atoa";
emit Changed(id, t);
return true;
}
}
Loading

0 comments on commit e714503

Please sign in to comment.