Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

3 6 2023 set get test #676

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions contracts/interpreter/ops/error/OpEnsure.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,26 @@ import "rain.lib.interpreter/LibOp.sol";
import "../../deploy/LibIntegrityCheck.sol";

error ExpressionError(
InterpreterState state,
Operand operand,
Pointer stackTop
bytes[] compiledSources,
uint256[] constants,
uint256[][] context,
uint256[] stack,
uint256 stackTopIndex,
uint256[] kvs,
FullyQualifiedNamespace namespace,
IInterpreterStoreV1 store,
Operand operand
);

/// @title OpEnsure
/// @notice Opcode for requiring some truthy values.
library OpEnsure {
using LibPointer for Pointer;
using LibUint256Array for Pointer;
using LibStackPointer for Pointer;
using LibOp for Pointer;
using LibIntegrityCheck for IntegrityCheckState;
using LibMemoryKV for MemoryKV;

function integrity(
IntegrityCheckState memory integrityCheckState_,
Expand All @@ -36,7 +45,17 @@ library OpEnsure {
uint256 a_;
(stackTop_, a_) = stackTop_.unsafePop();
if (a_ == 0) {
revert ExpressionError(state_, operand_, stackTop_);
revert ExpressionError(
state_.compiledSources,
state_.constantsBottom.unsafeSubWord().unsafeAsUint256Array(),
state_.context,
state_.stackBottom.unsafeSubWord().unsafeAsUint256Array(),
state_.stackBottom.unsafeToIndex(stackTop_),
state_.stateKV.toUint256Array(),
state_.namespace,
state_.store,
operand_
);
}
return stackTop_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ error UnexpectedOpMetaHash(bytes32 actualOpMeta);
/// immutable for any given interpreter so once the expression deployer is
/// constructed and has verified that this matches what the interpreter reports,
/// it can use this constant value to compile and serialize expressions.
bytes constant OPCODE_FUNCTION_POINTERS = hex"0c5e0c750c840d190d270d790de90e710f500fa6103f11e8122812461255126312721280128e129c12aa127212b812c6134413521360136e137d138c139b13aa13b913c813d713e613f51404141314611473148114b314c114cf14dd14eb14f91507151515231531153f154d155b156915771585159315a115af15bd15cc15db15ea15f81606161416221630163e164c17781800180f181e182c189e";
bytes constant OPCODE_FUNCTION_POINTERS = hex"0c5e0c750c840d190d270d790de90e710f500fa6103f11e8122812461255126312721280128e129c12aa127212b812c613c813d613e413f214011410141f142e143d144c145b146a14791488149714e514f715051537154515531561156f157d158b159915a715b515c315d115df15ed15fb160916171625163316411650165f166e167c168a169816a616b416c216d017fc1884189318a218b01922";

/// @dev Hash of the known interpreter bytecode.
bytes32 constant INTERPRETER_BYTECODE_HASH = bytes32(
0xba4c010b1990025e29241b302df5601101dbe9df778b00f1e865071f3aa32f15
0xf839f79ff5355e07b58582c8e93898f8d4d3d95bebe55b37761eaba608aaf1e8
);

/// @dev Hash of the known store bytecode.
Expand Down
145 changes: 145 additions & 0 deletions test/get-set-OP/1_deploy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { ethers } from "hardhat";
import {
EvaluableStructOutput,
Flow,
FlowInitializedEvent,
} from "../../typechain/contracts/flow/basic/Flow";
import { basicDeploy, getEvents, opMetaHash, RESERVE_ONE, standardEvaluableConfig } from "../../utils";
import { solidityKeccak256 } from "ethers/lib/utils";
import { ReserveToken18 } from "../../typechain/contracts/test/testToken";
import {
deployFlowClone,
flowImplementation,
} from "../../utils/deploy/flow/basic/deploy";
import { CloneFactory } from "../../typechain";

import { flowCloneFactory } from "../../utils/deploy/factory/cloneFactory";
import deploy1820 from "../../utils/deploy/registry1820/deploy";
import assert from "assert";
import { FlowConfig } from "../../utils/types/flow";
import { rainlang } from "../../utils/extensions/rainlang";
import { RAIN_FLOW_SENTINEL } from "../../utils/constants/sentinel";

export let flowConfig: FlowConfig;
export let endDate: number;
export let invoiceDataHash: string;
export let implementation: Flow;
export let cloneFactory: CloneFactory;

let signers: SignerWithAddress[];
let deployer: SignerWithAddress;
let client: SignerWithAddress; // caller
let contractor: SignerWithAddress; // caller
let flowContract: Flow;
let dispatchSet: EvaluableStructOutput,
dispatchGet: EvaluableStructOutput;

before(async () => {
signers = await ethers.getSigners();
// Deploy 1820
await deploy1820(signers[0]);
implementation = await flowImplementation();
//Deploy Clone Factory
cloneFactory = await flowCloneFactory();
deployer = signers[0];
client = signers[1];
contractor = signers[2];

const erc20 = (await basicDeploy("ReserveToken18", {})) as ReserveToken18;
await erc20.initialize();

endDate = Date.now();

invoiceDataHash = solidityKeccak256(
["uint256[]"],
[[client.address, contractor.address, RESERVE_ONE, endDate]]
);

const { sources: source1, constants: constants1 } =
await standardEvaluableConfig(
rainlang`
@${opMetaHash}

/* variables */
sentinel: ${RAIN_FLOW_SENTINEL},
:set(1 1),
/**
* erc1155 transfers
*/
transfererc1155slist: sentinel,

/**
* erc721 transfers
*/
transfererc721slist: sentinel,

/**
* er20 transfers
*/
transfererc20slist: sentinel;
`
);

const { sources: source2, constants: constants2 } =
await standardEvaluableConfig(
rainlang`
@${opMetaHash}

/* variables */
sentinel: ${RAIN_FLOW_SENTINEL},

:ensure(get(1)),
/**
* erc1155 transfers
*/
transfererc1155slist: sentinel,

/**
* erc721 transfers
*/
transfererc721slist: sentinel,

/**
* er20 transfers
*/
transfererc20slist: sentinel;
`
);

flowConfig = {
flows: [
{
sources: source1,
constants: constants1
},
{
sources: source2,
constants: constants2
}
]
}

const { flow } = await deployFlowClone(
deployer,
cloneFactory,
implementation,
flowConfig
);

const flowInitialized = (await getEvents(
flow.deployTransaction,
"FlowInitialized",
flow
)) as FlowInitializedEvent["args"][];

flowContract = flow;
dispatchSet = flowInitialized[0].evaluable;
dispatchGet = flowInitialized[1].evaluable;
});

it("Should deploy flow Contract", async () => {
assert(flowContract.address != undefined);
assert(dispatchSet != undefined);
assert(dispatchGet != undefined);
});
54 changes: 54 additions & 0 deletions test/get-set-OP/2_.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { ethers } from "hardhat";
import {
EvaluableStructOutput,
Flow,
FlowInitializedEvent,
} from "../../typechain/contracts/flow/basic/Flow";
import { getEvents } from "../../utils";
import { deployFlowClone } from "../../utils/deploy/flow/basic/deploy";
import {
cloneFactory,
flowConfig,
implementation,
} from "./1_deploy.test";

describe("GET-SET test", () => {
let signers: SignerWithAddress[];
let deployer: SignerWithAddress;
let flowContract: Flow;
let dispatchSet: EvaluableStructOutput,
dispatchGet: EvaluableStructOutput;

beforeEach(async () => {
signers = await ethers.getSigners();
deployer = signers[0];

const { flow } = await deployFlowClone(
deployer,
cloneFactory,
implementation,
flowConfig
);

const flowInitialized = (await getEvents(
flow.deployTransaction,
"FlowInitialized",
flow
)) as FlowInitializedEvent["args"][];

flowContract = flow;
dispatchSet = flowInitialized[0].evaluable;
dispatchGet = flowInitialized[1].evaluable;
});

it("Should be able to set and get the store value", async () => {
await flowContract
.connect(deployer)
.flow(dispatchSet, [], []);

await flowContract
.connect(deployer)
.flow(dispatchGet, [], []);
});
});