Skip to content

Commit

Permalink
removed deprecated extract tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michele-nuzzi committed May 20, 2024
1 parent ba69b02 commit 147c102
Show file tree
Hide file tree
Showing 24 changed files with 114 additions and 206 deletions.
9 changes: 8 additions & 1 deletion packages/onchain/src/IR/IRNodes/IRConst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,14 @@ export class IRConst
configurable: false
}
);

Object.defineProperty(
this, "isHashPresent", {
value: () => hash instanceof Uint8Array,
writable: false,
enumerable: true,
configurable: false
}
);
Object.defineProperty(
this, "markHashAsInvalid",
{
Expand Down
2 changes: 0 additions & 2 deletions packages/onchain/src/IR/IRNodes/IRConstr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export class IRConstr
configurable: false
}
);

Object.defineProperty(
this, "isHashPresent", {
value: () => hash instanceof Uint8Array,
Expand All @@ -116,7 +115,6 @@ export class IRConstr
configurable: false
}
);

Object.defineProperty(
this, "markHashAsInvalid",
{
Expand Down
10 changes: 9 additions & 1 deletion packages/onchain/src/IR/IRNodes/IRNative/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class IRNative
readonly tag!: IRNativeTag;
readonly hash!: Uint8Array;
markHashAsInvalid!: () => void;
isHashPresent: () => boolean;

readonly meta: IRNativeMetadata

Expand Down Expand Up @@ -123,7 +124,14 @@ export class IRNative
configurable: false
}
);

Object.defineProperty(
this, "isHashPresent", {
value: () => true,
writable: false,
enumerable: true,
configurable: false
}
);
Object.defineProperty(
this, "markHashAsInvalid",
{
Expand Down
1 change: 1 addition & 0 deletions packages/onchain/src/IR/utils/isIRParentTerm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IRApp } from "../IRNodes/IRApp";
import { IRCase } from "../IRNodes/IRCase";
import { IRConstr } from "../IRNodes/IRConstr";
import { IRDelayed } from "../IRNodes/IRDelayed";
import { IRForced } from "../IRNodes/IRForced";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { pmatch } from "../../../../PTypes"
import { pByteString, perror, toData } from "../../../../lib"
import { perror, pmatch, toData } from "../../../../lib"
import { PPubKeyHash } from "../../PubKey/PPubKeyHash"
import { PCredential } from "../PCredential"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { CEKConst, Machine } from "@harmoniclabs/plutus-machine";
import { pmatch } from "../../../../PTypes/PStruct/pmatch";
import { PValue } from "../../Value/PValue";
import { pInt } from "../../../../lib/std/int/pInt";
import { pBool } from "../../../../lib/std/bool/pBool";
import { fromData, perror, pisEmpty } from "../../../../lib";
import { fromData, perror, pisEmpty, pmatch } from "../../../../lib";
import { int } from "../../../../type_system";
import { _purp, beef32AsData, ctx, txInfo_v1 } from "../../../../../utils/test_utils";
import { ErrorUPLC } from "@harmoniclabs/uplc";
Expand Down Expand Up @@ -34,7 +33,7 @@ afterAll(() => {
});
//*/

describe("pmatch( <PScriptContext> )", () => {
describe.skip("pmatch( <PScriptContext> )", () => {

test("extract tx", () => {

Expand Down Expand Up @@ -114,10 +113,7 @@ describe("pmatch( <PScriptContext> )", () => {
test("inputs extracted", () => {
expect(
Machine.evalSimple(
pmatch( ctx )
.onPScriptContext( _ => _.extract("tx").in( ({ tx }) =>
tx.extract("inputs").in( ({ inputs }) => pisEmpty.$( inputs.tail ) )
))
pisEmpty.$( ctx.tx.inputs.tail )
)
).toEqual(
Machine.evalSimple(
Expand All @@ -128,10 +124,7 @@ describe("pmatch( <PScriptContext> )", () => {

test("outputs extracted", () => {

let term = pmatch( ctx )
.onPScriptContext( _ => _.extract("tx").in( ({ tx }) =>
tx.extract("outputs").in( ({ outputs }) => pisEmpty.$( outputs ) )
));
let term = pisEmpty.$( ctx.tx.outputs )

expect(
Machine.evalSimple(
Expand All @@ -149,16 +142,9 @@ describe("pmatch( <PScriptContext> )", () => {

expect(
Machine.evalSimple(
pmatch( ctx )
.onPScriptContext( _ => _.extract("tx").in( ({ tx }) =>
tx.extract("interval").in( ({ interval }) =>
interval.extract("from").in( ({ from }) =>
from.extract("bound").in( ({ bound }) =>

pmatch( bound )
pmatch( ctx.tx.interval.from.bound )
.onPFinite( _ => _.extract("_0").in( ({ _0 }) => _0 ))
._( _ => perror( int ) )
)))))
)
).toEqual(
Machine.evalSimple(
Expand All @@ -171,16 +157,7 @@ describe("pmatch( <PScriptContext> )", () => {
test("extract input value", () => {
expect(
Machine.evalSimple(
pmatch( ctx )
.onPScriptContext( _ => _.extract("tx").in( ({ tx }) =>

tx.extract("inputs").in( ({ inputs }) =>

inputs.head.extract("resolved").in( ({ resolved: input }) =>

input.extract("value").in( ({value}) => value )

))))
ctx.tx.inputs.head.resolved.value
)
).toEqual(
Machine.evalSimple(
Expand All @@ -191,8 +168,7 @@ describe("pmatch( <PScriptContext> )", () => {

test("extract tx only", () => {

const term = pmatch( ctx )
.onPScriptContext( _ => _.extract("tx").in( ({ tx }) => tx ));
const term = ctx.tx
const uplc = term.toUPLC(0);
let result = Machine.evalSimple(
uplc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PValue } from "../../../../V1/Value/PValue";
import { pBool, punMapData, toData } from "../../../../../lib";
import { tx_v2, beef32 } from "../../../../../../utils/test_utils";

describe("input value extraction", () => {
describe.skip("input value extraction", () => {

test("extract tx_v2.inputs", () => {

Expand Down Expand Up @@ -44,7 +44,7 @@ describe("input value extraction", () => {

test("extracts signatories", () => {

const term = tx_v2.extract("signatories").in( ({ signatories: sigs }) => sigs.head.eq("deadbeef") );
const term = tx_v2.signatories.head.eq("deadbeef");
const uplc = term.toUPLC(0);
const res = Machine.evalSimple(
uplc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("structList.head", () => {

expect(
Machine.evalSimple(
myList.head.extract("there").in( ({ there }) => there )
myList.head.there
)
).toEqual(
Machine.evalSimple(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Machine } from "@harmoniclabs/plutus-machine";
import { pstruct } from "..";
import { pDataI, pInt, phead, phoist, plam, pmakeUnit, toData } from "../../../lib"
import { getElemAtTerm, pDataI, pInt, phead, phoist, plam, pmakeUnit, pmatch, toData } from "../../../lib"
import { data, list, unit, int } from "../../../type_system";
import { getElemAtTerm, pmatch } from "../pmatch"


describe("getElemAtTerm", () => {
Expand Down Expand Up @@ -105,10 +104,7 @@ describe("getElemAtTerm", () => {
test("extract nested", () => {

const theTerm = pmatch( stuff )
.onStruct3( _ => _.extract("m").in( ({ m }) =>
m.extract("i").in( ({ i }) =>
i.extract("e").in( ({ e }) => e )
)));
.onStruct3( ({ m }) => m.i.e );

expect(
Machine.evalSimple(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { pstruct } from "../pstruct"
import { Term } from "../../../Term";
import { pmatch } from "../pmatch";
import { PMaybe } from "../../../lib/std/PMaybe/PMaybe";
import { pInt } from "../../../lib/std/int/pInt";
import { pmakeUnit } from "../../../lib/std/unit/pmakeUnit";
import { pByteString } from "../../../lib/std/bs/pByteString";
import { padd, pconsBs, pindexBs } from "../../../lib/builtins";
import { perror } from "../../../lib/perror";
import { TermType, bs, int, unit } from "../../../type_system/types";
import { pDataB, pDataI, toData } from "../../../lib";
import { pDataB, pDataI, pmatch, toData } from "../../../lib";
import { fromHex } from "@harmoniclabs/uint8array-utils";
import { ByteString } from "@harmoniclabs/bytestring";
import { CEKConst, Machine } from "@harmoniclabs/plutus-machine";
Expand All @@ -25,7 +24,7 @@ const SingleField = pstruct({
SingleField: { field: int }
})

describe("pmatch", () => {
describe.skip("pmatch", () => {

test("pmatch( <single field> )", () => {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { typeofGenericStruct } from "../pstruct"
import { PMaybe } from "../../../lib/std/PMaybe/PMaybe";
import { struct, tyVar } from "../../../type_system/types";
import { termTypeToString, typeExtends } from "../../../type_system";
import { typeofGenericStruct } from "../pgenericStruct";


describe("typeofGenericStruct", () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/onchain/src/pluts/PTypes/PStruct/pstruct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ export function pstruct<
{
assert(
isStructDefinition( def ),
"cannot construct 'PStruct' type; struct definition is not constant: " + structDefToString( def )
"cannot construct 'PStruct' type; struct definition is not constant: " +
structDefToString( def )
);

getMethods = typeof getMethods === "function" ? getMethods : _self_t => { return {} as SMethods; };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { PScriptContext } from "../../API/V2/ScriptContext/PScriptContext";
import { PCurrencySymbol } from "../../API/V1/Value/PCurrencySymbol";
import { compile } from "../compile";
import { bool, bs, data } from "../../type_system/types";
import { pmatch } from "../../PTypes/PStruct/pmatch";
import { pfn } from "../../lib/pfn";
import { pisEmpty } from "../../lib/builtins/list";
import { pByteString } from "../../lib/std/bs/pByteString";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { PScriptContext } from "../../API/V2/ScriptContext/PScriptContext";
import { PCurrencySymbol } from "../../API/V1/Value/PCurrencySymbol";
import { compile } from "../compile";
import { bool, bs, data } from "../../type_system/types";
import { pmatch } from "../../PTypes/PStruct/pmatch";
import { pfn } from "../../lib/pfn";
import { pisEmpty } from "../../lib/builtins/list";
import { pByteString } from "../../lib/std/bs/pByteString";
Expand All @@ -16,10 +15,11 @@ import { PBool } from "../../PTypes/PBool";
import { plet } from "../../lib/plet";
import { ByteString } from "@harmoniclabs/bytestring";
import { pshowInt } from "../../lib/show/int";
import { pmatch } from "../../lib/pmatch";

describe("NFTVendingMachine", () => {

test("it builds", () => {
test.skip("it builds", () => {

const nftPolicy = pfn([

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { PScriptContext } from "../../API/V2/ScriptContext/PScriptContext";
import { PTokenName } from "../../API/V1/Value/PTokenName";
import { PPubKeyHash } from "../../API/V1/PubKey/PPubKeyHash";
import { PAddress } from "../../API/V1/Address/PAddress";
import { pmatch } from "../../PTypes/PStruct/pmatch";
import { perror } from "../../lib/perror";
import { PTxOutRef } from "../../API/V1/Tx/PTxOutRef";
import { palias } from "../../PTypes/PAlias/palias";
Expand All @@ -40,6 +39,7 @@ import { ptraceError } from "../../lib/builtins/ptrace";
import { peqBs } from "../../lib/builtins/bs";
import { pmakeUnit } from "../../lib/std/unit/pmakeUnit";
import { addUtilityForType } from "../../lib/std/UtilityTerms/addUtilityForType";
import { pmatch } from "../../lib/pmatch";

const pvalueOf = phoist(
pfn([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PCurrencySymbol, PTxId, PTxOutRef, V2 } from "../../API";
import { pstruct, pmatch } from "../../PTypes";
import { pstruct } from "../../PTypes";
import { fromHex } from "@harmoniclabs/uint8array-utils";
import { _old_plet } from "../../lib/plet/old";
import { Cbor, CborBytes } from "@harmoniclabs/cbor";
Expand All @@ -17,6 +17,7 @@ import { pisEmpty } from "../../lib/builtins/list";
import { pData, pDataB, pDataI } from "../../lib/std/data/pData";
import { punsafeConvertType } from "../../lib/punsafeConvertType";
import { compile } from "../compile";
import { pmatch } from "../../lib/pmatch";

export const MintRdmr = pstruct({
Mint: {},
Expand All @@ -30,11 +31,8 @@ const oneShotNFT = pfn([
V2.PScriptContext.type

], bool)
(( utxo, rdmr, ctx ) =>
(( utxo, rdmr, { tx, purpose } ) =>

ctx.extract("tx","purpose").in( ({ tx, purpose }) =>
tx.extract("inputs","mint").in( tx =>

plet(
pmatch( purpose )
.onMinting( mint => mint.currencySym )
Expand All @@ -44,11 +42,7 @@ const oneShotNFT = pfn([
pmatch( rdmr )
.onMint( _ =>

tx.inputs.some( input => {

return input.extract("utxoRef").in( ({ utxoRef }) => utxoRef.eq( utxo ) )

})
tx.inputs.some( ({ utxoRef }) => utxoRef.eq( utxo ) )
.and(

tx.mint.some( entry => {
Expand Down Expand Up @@ -90,7 +84,7 @@ const oneShotNFT = pfn([
)
)

)))
)
)

const _oneShotNFT = pfn([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { compile, scriptToJsonFormat } from "../compile"
import { PScriptContext } from "../../API/V1/ScriptContext/PScriptContext"
import { pmatch } from "../../PTypes/PStruct/pmatch"
import { PTxInInfo } from "../../API/V1/Tx/PTxInInfo"
import { makeValidator } from "../makeScript"
import { PTxInfo } from "../../API/V1/ScriptContext/PTxInfo/PTxInfo"
Expand Down
Loading

0 comments on commit 147c102

Please sign in to comment.