Skip to content

Commit

Permalink
Adjust to match latest domainapi interface
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Richardson <[email protected]>
  • Loading branch information
awrichar committed Aug 15, 2024
1 parent 2f0f624 commit 1d412f2
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 26 deletions.
1 change: 1 addition & 0 deletions domains/noto/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ task copySolidity(type: Copy) {
inputs.files(configurations.contractCompile)
from fileTree(configurations.contractCompile.asPath) {
include 'contracts/noto/NotoFactory.sol/NotoFactory.json'
include 'contracts/noto/Noto.sol/Noto.json'
}
into 'internal/noto/abis'

Expand Down
8 changes: 4 additions & 4 deletions domains/noto/internal/noto/e2e_noto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import (
"github.com/stretchr/testify/assert"
)

// TODO: fix things that should not be hard-coded
var (
toDomain = "to-domain"
testbedAddr = "http://127.0.0.1:49600"
grpcAddr = "dns:localhost:49601"
account1 = "0x9180ff8fa5c502b9bfe5dfeaf477e157dbfaba5c"
notaryName = "notary1"
notaryAddr = "0x9180ff8fa5c502b9bfe5dfeaf477e157dbfaba5c"
)

func TestNoto(t *testing.T) {
Expand All @@ -57,7 +57,7 @@ func TestNoto(t *testing.T) {
defer cancel()

log.L(ctx).Infof("Calling testbed_deployBytecode")
rpcerr := rpc.CallRPC(callCtx, &addressResult, "testbed_deployBytecode", account1, domain.Factory.Bytecode.String())
rpcerr := rpc.CallRPC(callCtx, &addressResult, "testbed_deployBytecode", notaryName, domain.Factory.ABI, domain.Factory.Bytecode.String(), `{}`)
if rpcerr != nil {
assert.NoError(t, rpcerr.Error())
}
Expand All @@ -72,7 +72,7 @@ func TestNoto(t *testing.T) {

log.L(ctx).Infof("Calling testbed_deploy")
rpcerr = rpc.CallRPC(callCtx, &objResult, "testbed_deploy", "noto", &NotoConstructor{
Notary: account1,
Notary: notaryAddr,
})
if rpcerr != nil {
assert.NoError(t, rpcerr.Error())
Expand Down
42 changes: 31 additions & 11 deletions domains/noto/internal/noto/noto.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ import (
//go:embed abis/NotoFactory.json
var notoFactoryJSON []byte // From "gradle copySolidity"

//go:embed abis/Noto.json
var notoJSON []byte // From "gradle copySolidity"

type Config struct {
FactoryAddress string `json:"factoryAddress" yaml:"factoryAddress"`
}
Expand All @@ -48,6 +51,7 @@ type SolidityBuild struct {

type Noto struct {
Factory SolidityBuild
Contract SolidityBuild
conn *grpc.ClientConn
dest *string
client pb.KataMessageServiceClient
Expand Down Expand Up @@ -79,23 +83,34 @@ func New(ctx context.Context, addr string) (*Noto, error) {
return nil, fmt.Errorf("failed to connect gRPC: %v", err)
}

factory, err := loadABI()
factory, err := loadNotoFactoryABI()
if err != nil {
return nil, err
}
contract, err := loadNotoABI()
if err != nil {
return nil, err
}

d := &Noto{
conn: conn,
client: pb.NewKataMessageServiceClient(conn),
Factory: factory,
conn: conn,
client: pb.NewKataMessageServiceClient(conn),
Factory: factory,
Contract: contract,
}
return d, d.waitForReady(ctx)
}

func loadABI() (SolidityBuild, error) {
var notoFactoryBuild SolidityBuild
err := json.Unmarshal(notoFactoryJSON, &notoFactoryBuild)
return notoFactoryBuild, err
func loadNotoFactoryABI() (SolidityBuild, error) {
var build SolidityBuild
err := json.Unmarshal(notoFactoryJSON, &build)
return build, err
}

func loadNotoABI() (SolidityBuild, error) {
var build SolidityBuild
err := json.Unmarshal(notoJSON, &build)
return build, err
}

func (d *Noto) waitForReady(ctx context.Context) error {
Expand Down Expand Up @@ -206,11 +221,16 @@ func (d *Noto) handleMessage(ctx context.Context, message *pb.Message) error {
if err != nil {
return err
}
notoJSON, err := json.Marshal(d.Contract.ABI)
if err != nil {
return err
}

response := &pb.ConfigureDomainResponse{
DomainConfig: &pb.DomainConfig{
FactoryContractAddress: config.FactoryAddress,
FactoryContractAbiJson: string(factoryJSON),
PrivateContractAbiJson: string(notoJSON),
ConstructorAbiJson: constructorAbi,
AbiStateSchemasJson: []string{},
},
Expand Down Expand Up @@ -255,10 +275,10 @@ func (d *Noto) handleMessage(ctx context.Context, message *pb.Message) error {

response := &pb.PrepareDeployTransactionResponse{
Transaction: &pb.BaseLedgerTransaction{
FunctionName: "deploy",
ParamsJson: `{"notary": "` + params.Notary + `"}`,
SigningAddress: params.Notary,
FunctionName: "deploy",
ParamsJson: `{"txId": "` + m.Transaction.TransactionId + `", "notary": "` + params.Notary + `"}`,
},
SigningAddress: params.Notary,
}
if err := d.sendReply(ctx, message, response); err != nil {
return err
Expand Down
10 changes: 9 additions & 1 deletion solidity/contracts/noto/Noto.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import {NotoBase} from "./NotoBase.sol";
* Noto variant which requires all transfers/approvals to be submitted by the notary.
*/
contract Noto is NotoBase {
constructor(address notary) NotoBase(notary) {}
event PaladinNewSmartContract_V0(
bytes32 indexed txId,
address indexed domain,
bytes data
);

constructor(bytes32 txId, address domain, address notary) NotoBase(notary) {
emit PaladinNewSmartContract_V0(txId, domain, "");
}

function transfer(
bytes32[] memory inputs,
Expand Down
9 changes: 2 additions & 7 deletions solidity/contracts/noto/NotoFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ pragma solidity ^0.8.20;
import {Noto} from "./Noto.sol";

contract NotoFactory {
event PaladinNewSmartContract_V0(
address indexed contractAddress
);

function deploy(address notary) external {
Noto n = new Noto(notary);
emit PaladinNewSmartContract_V0(address(n));
function deploy(bytes32 txId, address notary) external {
new Noto(txId, address(this), notary);
}
}
6 changes: 5 additions & 1 deletion solidity/test/noto/Noto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ describe("Noto", function () {
const [notary, other] = await ethers.getSigners();

const Noto = await ethers.getContractFactory("Noto");
const noto = await Noto.deploy(notary.address);
const noto = await Noto.deploy(
randomBytes32(),
"0xab5a1b758fdabfa31542bf50de1e1689ab64db6e",
notary.address
);

return { noto, notary, other };
}
Expand Down
4 changes: 2 additions & 2 deletions testinfra/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ task stopTestInfra(type: DockerCompose) {
task removeBesuBootstrapTool(type: Exec, dependsOn: stopTestInfra) {
executable "docker"
args "rmi", "-f", "paladin/besu_bootstrap"

ignoreExitValue = true
errorOutput OutputStream.nullOutputStream()
ignoreExitValue true
}

task clean(type: Delete, dependsOn: [tasks.removeBesuBootstrapTool, tasks.stopTestInfra]) {
Expand Down

0 comments on commit 1d412f2

Please sign in to comment.