@clarigen/test 1.0.0-next.12 → 1.0.0-next.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -4
- package/dist/index.mjs +7 -7
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var H=Object.defineProperty,j=Object.defineProperties;var D=Object.getOwnPropertyDescriptors;var R=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var T=(r,t,e)=>t in r?H(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,c=(r,t)=>{for(var e in t||(t={}))L.call(t,e)&&T(r,e,t[e]);if(R)for(var e of R(t))G.call(t,e)&&T(r,e,t[e]);return r},l=(r,t)=>j(r,D(t));var _core = require('@clarigen/core');var _crypto = require('micro-stacks/crypto');var _transactions = require('micro-stacks/transactions');var _nativebin = require('@clarigen/native-bin');var _clarity = require('micro-stacks/clarity');var v=async({contractAddress:r,senderAddress:t,functionName:e,provider:n,args:s=[]})=>{let i=await n.runCommand(["execute","--costs","--assets",n.dbFilePath,r,e,t,...s]);process.env.PRINT_CLARIGEN_STDERR&&i.stderr&&console.log(i.stderr);let o=JSON.parse(i.stdout);if(o&&"error"in o)throw new Error(`Transaction error: ${JSON.stringify(o.error,null,2)}`);if(i.exitCode!==0)throw new Error(`Execution error: ${i.stderr}`);return l(c({},o),{stderr:i.stderr})},y=async({contractAddress:r,code:t,provider:e})=>{let n=await e.runCommand(["eval_at_chaintip","--costs",r,e.dbFilePath],{stdin:t});process.env.PRINT_CLARIGEN_STDERR&&n.stderr&&console.log(n.stderr);let s=JSON.parse(n.stdout);if(!s.success)throw new Error(JSON.stringify(s.error,null,2));return l(c({},s),{stderr:n.stderr})},d= exports.evalJson =({contractAddress:r,functionName:t,provider:e,args:n=[]})=>{let s=`(${t} ${n.join(" ")})`;return y({contractAddress:r,provider:e,code:s})};function tt(r){return r?"deployer"in r?Object.values(r).map(t=>({amount:t.balance,principal:t.address})):Array.isArray(r)?r:[]:[]}function rt(r,t){return typeof t=="bigint"?`${t}n`:t}function et(r){return JSON.stringify(r,rt).replace(/"(-?\d+)n"/g,(e,n)=>n)}var f=async({allocations:r,testnet:t=!0}={})=>{let e=_nativebin.getDefaultBinaryFilePath.call(void 0, ),n=_nativebin.getTempFilePath.call(void 0, ),s=tt(r),i=new (0, _nativebin.NativeClarityBinProvider)(n,e),o=["initialize","-",n];return t&&o.push("--testnet"),await i.runCommand(o,{stdin:et(s)}),i};async function m({contractIdentifier:r,contractFilePath:t,provider:e}){let n=await e.runCommand(["launch",r,t,e.dbFilePath,"--costs","--assets"]);if(_nativebin.hasStdErr.call(void 0, n.stderr))throw new Error(`Error on ${t}:
|
|
2
2
|
${n.stderr}
|
|
3
3
|
`);let s=JSON.parse(n.stdout);if(s.error){let{initialization:i}=s.error;if(i!=null&&i.includes(`
|
|
4
4
|
Near:
|
|
5
5
|
`)){let[o,a]=i.split(`
|
|
6
6
|
Near:
|
|
7
|
-
`),p="",
|
|
7
|
+
`),p="",x=/start_line: (\d+),/.exec(a);throw x&&(p=x[1]),new Error(`Error on ${t}:
|
|
8
8
|
${o}
|
|
9
9
|
${p?`Near line ${p}`:""}
|
|
10
10
|
Raw trace:
|
|
11
11
|
${a}
|
|
12
12
|
`)}throw new Error(`Error on ${t}:
|
|
13
13
|
${JSON.stringify(s.error,null,2)}
|
|
14
|
-
`)}}function
|
|
15
|
-
`).map(t=>t.slice(62))}function
|
|
14
|
+
`)}}function k(r){return _core.filterEvents.call(void 0, r,_core.CoreNodeEventType.ContractEvent).map(t=>{let e=t.contract_event.raw_value,n=_clarity.hexToCV.call(void 0, e);return _core.cvToValue.call(void 0, n)})}var _path = require('path');var _common = require('micro-stacks/common');var u="ST000000000000000000002AMW42H.clarigen-test-utils";async function N(r){let t=_path.join.call(void 0, __dirname,"..","..","contracts","test-utils.clar");__dirname.includes("dist")&&(t=_path.join.call(void 0, __dirname,"..","contracts","test-utils.clar")),await m({contractIdentifier:u,provider:r,contractFilePath:t})}function g(r){return"clarityBin"in r?r.clarityBin:r}async function st(r){let t=g(r),{output_serialized:e}=await d({contractAddress:u,functionName:"get-block-height",args:[],provider:t}),n=_clarity.hexToCV.call(void 0, e);return _core.cvToValue.call(void 0, n)}async function it(r){let t=g(r);await v({contractAddress:u,functionName:"mine-block",args:[],provider:t,senderAddress:"ST000000000000000000002AMW42H"})}async function ot(r,t){let e=_common.intToBigInt.call(void 0, r);for(let n=0;n<e;n++)await it(t)}async function at(r,t){let e=g(r),{output_serialized:n}=await d({contractAddress:u,functionName:"get-stx-balance",args:[`'${t}`],provider:e}),s=_clarity.hexToCV.call(void 0, n);return _core.cvToValue.call(void 0, s)}function pt(r=_crypto.StacksNetworkVersion.testnetP2PKH){let t=_transactions.makeRandomPrivKey.call(void 0, ),e=_transactions.getPublicKeyFromStacksPrivateKey.call(void 0, t);return _crypto.publicKeyToStxAddress.call(void 0, e.data,r)}function V(r){return r.map(t=>_core.cvToString.call(void 0, t))}function E(r){return`${r.contractAddress}.${r.contractName}`}function $(r){return r===""?[]:r.split(`
|
|
15
|
+
`).map(t=>t.slice(62))}function S(r){let t=_clarity.hexToCV.call(void 0, r.output_serialized);return{value:_core.cvToValue.call(void 0, t,!0),clarityValue:t,logs:$(r.stderr),costs:r.costs}}async function I(r,t){let e=await d({functionName:r.function.name,args:V(r.functionArgs),contractAddress:E(r),provider:t});return S(e)}async function P({contractAddress:r,code:t,bin:e}){let n=await y({contractAddress:r,code:t,provider:e});return S(n)}async function J({tx:r,senderAddress:t,bin:e}){let n=await v({contractAddress:E(r),senderAddress:t,provider:e,functionName:r.function.name,args:V(r.functionArgs)}),s=_clarity.hexToCV.call(void 0, n.output_serialized),o={value:_core.cvToValue.call(void 0, s),logs:$(n.stderr),costs:n.costs};return n.success?l(c({},o),{isOk:!0,response:_clarity.responseOkCV.call(void 0, s),assets:n.assets,events:n.events,prints:k(n.events)}):l(c({},o),{isOk:!1,response:_clarity.responseErrorCV.call(void 0, s)})}async function F({map:r,bin:t}){let e=`(map-get? ${r.map.name} ${_core.cvToString.call(void 0, r.key)})`;return(await P({contractAddress:E(r),code:e,bin:t})).value}var z=class{constructor(t){this.clarityBin=t}static async fromContracts(t,e={}){let n=e.clarityBin||await f({allocations:e.accounts}),s={};await N(n);for(let o in t)if(Object.prototype.hasOwnProperty.call(t,o)){let a=t[o],p=_core.getContractIdentifier.call(void 0, a);await m({contractIdentifier:p,contractFilePath:a.contractFile,provider:n});let b=a.contract(a.address,a.name);s[o]={identifier:_core.getContractIdentifier.call(void 0, a),contract:b}}let i=new this(n);return{deployed:s,provider:i}}ro(t){return I(t,this.clarityBin)}async rov(t){return(await this.ro(t)).value}async roOk(t){let e=await this.ro(t);return e.value.match(n=>l(c({},e),{value:n}),n=>{throw new Error(`Expected OK, received error: ${n}`)})}async roErr(t){let e=await this.ro(t);return e.value.match(n=>{throw new Error(`Expected err, received ok: ${n}`)},n=>l(c({},e),{value:n}))}async rovOk(t){return(await this.roOk(t)).value}async rovErr(t){return(await this.roErr(t)).value}tx(t,e){return J({tx:t,senderAddress:e,bin:this.clarityBin})}async txOk(t,e){let n=await this.tx(t,e);if(!n.isOk)throw new Error(`Expected OK, received error: ${n.value}`);return n}async txErr(t,e){let n=await this.tx(t,e);if(n.isOk)throw new Error(`Expected Err, received ok: ${n.value}`);return n}evalCode(t,e=u){return P({contractAddress:e,code:t,bin:this.clarityBin})}async eval(t,e=u){return(await this.evalCode(t,e)).value}mapGet(t){return F({map:t,bin:this.clarityBin})}};exports.TestProvider = z; exports.createClarityBin = f; exports.evalJson = d; exports.executeJson = v; exports.getBlockHeight = st; exports.getStxBalance = at; exports.makeRandomAddress = pt; exports.mineBlocks = ot;
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
1
|
+
var H=Object.defineProperty,L=Object.defineProperties;var j=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var G=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var k=(r,t,e)=>t in r?H(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,c=(r,t)=>{for(var e in t||(t={}))G.call(t,e)&&k(r,e,t[e]);if(T)for(var e of T(t))U.call(t,e)&&k(r,e,t[e]);return r},l=(r,t)=>L(r,j(t));import{fileURLToPath as M}from"url";import W from"path";var q=()=>M(import.meta.url),Q=()=>W.dirname(q()),u=Q();import{getContractIdentifier as z}from"@clarigen/core";import{publicKeyToStxAddress as mt,StacksNetworkVersion as vt}from"micro-stacks/crypto";import{getPublicKeyFromStacksPrivateKey as Ct,makeRandomPrivKey as yt}from"micro-stacks/transactions";import{getTempFilePath as X,NativeClarityBinProvider as Y,getDefaultBinaryFilePath as Z,hasStdErr as tt}from"@clarigen/native-bin";import{CoreNodeEventType as rt,cvToValue as et,filterEvents as nt}from"@clarigen/core";import{hexToCV as st}from"micro-stacks/clarity";var v=async({contractAddress:r,senderAddress:t,functionName:e,provider:n,args:s=[]})=>{let o=await n.runCommand(["execute","--costs","--assets",n.dbFilePath,r,e,t,...s]);process.env.PRINT_CLARIGEN_STDERR&&o.stderr&&console.log(o.stderr);let i=JSON.parse(o.stdout);if(i&&"error"in i)throw new Error(`Transaction error: ${JSON.stringify(i.error,null,2)}`);if(o.exitCode!==0)throw new Error(`Execution error: ${o.stderr}`);return l(c({},i),{stderr:o.stderr})},f=async({contractAddress:r,code:t,provider:e})=>{let n=await e.runCommand(["eval_at_chaintip","--costs",r,e.dbFilePath],{stdin:t});process.env.PRINT_CLARIGEN_STDERR&&n.stderr&&console.log(n.stderr);let s=JSON.parse(n.stdout);if(!s.success)throw new Error(JSON.stringify(s.error,null,2));return l(c({},s),{stderr:n.stderr})},p=({contractAddress:r,functionName:t,provider:e,args:n=[]})=>{let s=`(${t} ${n.join(" ")})`;return f({contractAddress:r,provider:e,code:s})};function ot(r){return r?"deployer"in r?Object.values(r).map(t=>({amount:t.balance,principal:t.address})):Array.isArray(r)?r:[]:[]}function it(r,t){return typeof t=="bigint"?`${t}n`:t}function at(r){return JSON.stringify(r,it).replace(/"(-?\d+)n"/g,(e,n)=>n)}var g=async({allocations:r,testnet:t=!0}={})=>{let e=Z(),n=X(),s=ot(r),o=new Y(n,e),i=["initialize","-",n];return t&&i.push("--testnet"),await o.runCommand(i,{stdin:at(s)}),o};async function y({contractIdentifier:r,contractFilePath:t,provider:e}){let n=await e.runCommand(["launch",r,t,e.dbFilePath,"--costs","--assets"]);if(tt(n.stderr))throw new Error(`Error on ${t}:
|
|
2
2
|
${n.stderr}
|
|
3
|
-
`);let s=JSON.parse(n.stdout);if(s.error){let{initialization:
|
|
3
|
+
`);let s=JSON.parse(n.stdout);if(s.error){let{initialization:o}=s.error;if(o!=null&&o.includes(`
|
|
4
4
|
Near:
|
|
5
|
-
`)){let[
|
|
5
|
+
`)){let[i,a]=o.split(`
|
|
6
6
|
Near:
|
|
7
|
-
`),m="",
|
|
8
|
-
${
|
|
7
|
+
`),m="",R=/start_line: (\d+),/.exec(a);throw R&&(m=R[1]),new Error(`Error on ${t}:
|
|
8
|
+
${i}
|
|
9
9
|
${m?`Near line ${m}`:""}
|
|
10
10
|
Raw trace:
|
|
11
11
|
${a}
|
|
12
12
|
`)}throw new Error(`Error on ${t}:
|
|
13
13
|
${JSON.stringify(s.error,null,2)}
|
|
14
|
-
`)}}function
|
|
15
|
-
`).map(t=>t.slice(62))}function
|
|
14
|
+
`)}}function O(r){return nt(r,rt.ContractEvent).map(t=>{let e=t.contract_event.raw_value,n=st(e);return et(n)})}import{hexToCV as h}from"micro-stacks/clarity";import{join as w}from"path";import{cvToValue as N}from"@clarigen/core";import{intToBigInt as ct}from"micro-stacks/common";var d="ST000000000000000000002AMW42H.clarigen-test-utils";async function A(r){let t=w(u,"..","..","contracts","test-utils.clar");u.includes("dist")&&(t=w(u,"..","contracts","test-utils.clar")),await y({contractIdentifier:d,provider:r,contractFilePath:t})}function E(r){return"clarityBin"in r?r.clarityBin:r}async function lt(r){let t=E(r),{output_serialized:e}=await p({contractAddress:d,functionName:"get-block-height",args:[],provider:t}),n=h(e);return N(n)}async function ut(r){let t=E(r);await v({contractAddress:d,functionName:"mine-block",args:[],provider:t,senderAddress:"ST000000000000000000002AMW42H"})}async function dt(r,t){let e=ct(r);for(let n=0;n<e;n++)await ut(t)}async function pt(r,t){let e=E(r),{output_serialized:n}=await p({contractAddress:d,functionName:"get-stx-balance",args:[`'${t}`],provider:e}),s=h(n);return N(s)}function ft(r=vt.testnetP2PKH){let t=yt(),e=Ct(t);return mt(e.data,r)}import{cvToString as B,cvToValue as _}from"@clarigen/core";import{hexToCV as V,responseErrorCV as gt,responseOkCV as Et}from"micro-stacks/clarity";function $(r){return r.map(t=>B(t))}function P(r){return`${r.contractAddress}.${r.contractName}`}function S(r){return r===""?[]:r.split(`
|
|
15
|
+
`).map(t=>t.slice(62))}function I(r){let t=V(r.output_serialized);return{value:_(t,!0),clarityValue:t,logs:S(r.stderr),costs:r.costs}}async function J(r,t){let e=await p({functionName:r.function.name,args:$(r.functionArgs),contractAddress:P(r),provider:t});return I(e)}async function b({contractAddress:r,code:t,bin:e}){let n=await f({contractAddress:r,code:t,provider:e});return I(n)}async function F({tx:r,senderAddress:t,bin:e}){let n=await v({contractAddress:P(r),senderAddress:t,provider:e,functionName:r.function.name,args:$(r.functionArgs)}),s=V(n.output_serialized),i={value:_(s),logs:S(n.stderr),costs:n.costs};return n.success?l(c({},i),{isOk:!0,response:Et(s),assets:n.assets,events:n.events,prints:O(n.events)}):l(c({},i),{isOk:!1,response:gt(s)})}async function K({map:r,bin:t}){let e=`(map-get? ${r.map.name} ${B(r.key)})`;return(await b({contractAddress:P(r),code:e,bin:t})).value}var D=class{constructor(t){this.clarityBin=t}static async fromContracts(t,e={}){let n=e.clarityBin||await g({allocations:e.accounts}),s={};await A(n);for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let a=t[i],m=z(a);await y({contractIdentifier:m,contractFilePath:a.contractFile,provider:n});let x=a.contract(a.address,a.name);s[i]={identifier:z(a),contract:x}}let o=new this(n);return{deployed:s,provider:o}}ro(t){return J(t,this.clarityBin)}async rov(t){return(await this.ro(t)).value}async roOk(t){let e=await this.ro(t);return e.value.match(n=>l(c({},e),{value:n}),n=>{throw new Error(`Expected OK, received error: ${n}`)})}async roErr(t){let e=await this.ro(t);return e.value.match(n=>{throw new Error(`Expected err, received ok: ${n}`)},n=>l(c({},e),{value:n}))}async rovOk(t){return(await this.roOk(t)).value}async rovErr(t){return(await this.roErr(t)).value}tx(t,e){return F({tx:t,senderAddress:e,bin:this.clarityBin})}async txOk(t,e){let n=await this.tx(t,e);if(!n.isOk)throw new Error(`Expected OK, received error: ${n.value}`);return n}async txErr(t,e){let n=await this.tx(t,e);if(n.isOk)throw new Error(`Expected Err, received ok: ${n.value}`);return n}evalCode(t,e=d){return b({contractAddress:e,code:t,bin:this.clarityBin})}async eval(t,e=d){return(await this.evalCode(t,e)).value}mapGet(t){return K({map:t,bin:this.clarityBin})}};export{D as TestProvider,g as createClarityBin,p as evalJson,v as executeJson,lt as getBlockHeight,pt as getStxBalance,ft as makeRandomAddress,dt as mineBlocks};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.0-next.
|
|
2
|
+
"version": "1.0.0-next.13",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"types": "./dist/index.d.ts",
|
|
5
5
|
"main": "./dist/index.js",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "9b21b2e4e5f684bd0a862a3fb35a3661951a33fb"
|
|
37
37
|
}
|