Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

add support for the lib #17

Open
wants to merge 3 commits into
base: main
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
9 changes: 4 additions & 5 deletions package.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please explain the changes in package.json?

Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@
"@types/node": "^18.11.18",
"jest": "^29.3.1",
"release-it": "^15.6.0",
"@ton/core": ">=0.49.2",
"@ton/core": "0.56.3",
"@ton/crypto": "^3.2.0",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typescript": "^4.9.4",
"@tact-lang/ton-abi": "^0.0.3"
},
"peerDependencies": {
"@ton/core": ">=0.49.2",
"@tact-lang/ton-abi": "^0.0.3",
"@ton/core": "0.56.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is not a peer dependency anymore?

"@ton/crypto": "^3.2.0",
"ton-abi": "^0.0.1"
},

"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
Expand Down
6 changes: 4 additions & 2 deletions src/emulator/ContractExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class ContractExecutor {
#index = 0;
#verbosity: Verbosity | null = null;
#name: string | null = null;
#libs: Cell | null = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, what problem does this solve for you?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i need to mock a contract, which is a lib deployed on master chain. and i get the code from master chain. but i find that i need to pass the lib along with the code, so that it can work for me


private constructor(state: Account, system: ContractSystem) {
this.system = system;
Expand Down Expand Up @@ -167,10 +168,11 @@ export class ContractExecutor {
* @param data contract data
* @param balance contract balance
*/
override = (code: Cell, data: Cell, balance: bigint) => {
override = (code: Cell, data: Cell, balance: bigint, libs: Cell|null) => {
this.#balance = balance;
this.#state = createAccount({ code, data, address: this.address, balance });
this.#last = { lt: 0n, hash: 0n };
this.#libs = libs;
}

get = async (method: string | number, stack?: Maybe<TupleItem[]>): Promise<GetMethodResult> => {
Expand Down Expand Up @@ -261,7 +263,7 @@ export class ContractExecutor {
// Execute transaction
let res = await this.system.bindings.transaction({
config: this.system.config,
libs: null,
libs: this.#libs,
verbosity: verbosity,
shardAccount: beginCell().store(storeShardAccount({ account: this.#state, lastTransactionHash: this.#last.hash, lastTransactionLt: this.#last.lt })).endCell(),
message: beginCell().store(storeMessage(msg)).endCell(),
Expand Down
4 changes: 2 additions & 2 deletions src/emulator/ContractSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export class ContractSystem {
* @param data
* @param balance
*/
override(address: Address, code: Cell, data: Cell, balance: bigint) {
this.contract(address).override(code, data, balance);
override(address: Address, code: Cell, data: Cell, balance: bigint, lib:Cell) {
this.contract(address).override(code, data, balance, lib);
}

/**
Expand Down