From 3fb84366b34718c1455049c8902b73ae9976cd99 Mon Sep 17 00:00:00 2001 From: vishal Date: Sat, 3 Jun 2023 17:29:44 +0530 Subject: [PATCH 1/3] added set get op test --- test/get-set-OP/1_deploy.test.ts | 145 +++++++++++++++++++++++++++++++ test/get-set-OP/2_.test.ts | 54 ++++++++++++ 2 files changed, 199 insertions(+) create mode 100644 test/get-set-OP/1_deploy.test.ts create mode 100644 test/get-set-OP/2_.test.ts diff --git a/test/get-set-OP/1_deploy.test.ts b/test/get-set-OP/1_deploy.test.ts new file mode 100644 index 000000000..858128a74 --- /dev/null +++ b/test/get-set-OP/1_deploy.test.ts @@ -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); +}); diff --git a/test/get-set-OP/2_.test.ts b/test/get-set-OP/2_.test.ts new file mode 100644 index 000000000..3e28eca17 --- /dev/null +++ b/test/get-set-OP/2_.test.ts @@ -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.only("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, [], []); + }); +}); From 7429acf682e84e04af0bc7f8d5314c0e936e3bae Mon Sep 17 00:00:00 2001 From: vishal Date: Sat, 3 Jun 2023 18:07:51 +0530 Subject: [PATCH 2/3] removed only tag from test --- test/get-set-OP/2_.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/get-set-OP/2_.test.ts b/test/get-set-OP/2_.test.ts index 3e28eca17..d441d3046 100644 --- a/test/get-set-OP/2_.test.ts +++ b/test/get-set-OP/2_.test.ts @@ -13,7 +13,7 @@ import { implementation, } from "./1_deploy.test"; -describe.only("GET-SET test", () => { +describe("GET-SET test", () => { let signers: SignerWithAddress[]; let deployer: SignerWithAddress; let flowContract: Flow; From 39e49b4dd954fa1db542f820e77f87e0b7ea342b Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Tue, 6 Jun 2023 20:30:00 +0400 Subject: [PATCH 3/3] make expression error useful --- contracts/interpreter/ops/error/OpEnsure.sol | 27 ++++++++++++++++--- .../RainterpreterExpressionDeployer.sol | 4 +-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/contracts/interpreter/ops/error/OpEnsure.sol b/contracts/interpreter/ops/error/OpEnsure.sol index cea1a31c8..83eef8133 100644 --- a/contracts/interpreter/ops/error/OpEnsure.sol +++ b/contracts/interpreter/ops/error/OpEnsure.sol @@ -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_, @@ -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_; } diff --git a/contracts/interpreter/shared/RainterpreterExpressionDeployer.sol b/contracts/interpreter/shared/RainterpreterExpressionDeployer.sol index 1b2a87d95..425869897 100644 --- a/contracts/interpreter/shared/RainterpreterExpressionDeployer.sol +++ b/contracts/interpreter/shared/RainterpreterExpressionDeployer.sol @@ -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.