Skip to content

Commit 281384a

Browse files
committed
feat: extra currency
chore: bump version, changelog
1 parent 33352f6 commit 281384a

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.5.0] - 2025-01-17
9+
10+
### Added
11+
12+
- Added extra currency (`ec`) matcher
13+
814
## [0.4.2] - 2023-11-25
915

1016
### Fixed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ton/test-utils",
3-
"version": "0.4.2",
3+
"version": "0.5.0",
44
"main": "dist/index.js",
55
"license": "MIT",
66
"description": "Utilities for writing tests for smart contract systems in TON",

src/test/transaction.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AccountStatus, Address, Cell, Transaction } from "@ton/core";
1+
import { AccountStatus, Address, Cell, CurrencyCollection, Transaction } from "@ton/core";
22
import { inspect } from "node-inspect-extracted";
33
import { CompareResult } from "./interface";
44

@@ -7,6 +7,7 @@ export type FlatTransaction = {
77
to?: Address
88
on?: Address
99
value?: bigint
10+
ec?: [number, bigint][]
1011
body?: Cell
1112
inMessageBounced?: boolean
1213
inMessageBounceable?: boolean
@@ -42,6 +43,15 @@ function extractOp(body: Cell): number | undefined {
4243
}
4344
}
4445

46+
function extractEc(cc: CurrencyCollection): [number, bigint][] {
47+
const r: [number, bigint][] = [];
48+
for (const [k, v] of cc.other ?? []) {
49+
r.push([k, v]);
50+
}
51+
r.sort((a, b) => a[0] - b[0]);
52+
return r;
53+
}
54+
4555
export function flattenTransaction(tx: Transaction): FlatTransaction {
4656
return {
4757
lt: tx.lt,
@@ -55,6 +65,7 @@ export function flattenTransaction(tx: Transaction): FlatTransaction {
5565
to: tx.inMessage.info.dest as Address,
5666
on: tx.inMessage.info.dest as Address,
5767
value: tx.inMessage.info.type === 'internal' ? tx.inMessage.info.value.coins : undefined,
68+
ec: tx.inMessage.info.type === 'internal' ? extractEc(tx.inMessage.info.value) : undefined,
5869
body: tx.inMessage.body,
5970
inMessageBounced: tx.inMessage.info.type === 'internal' ? tx.inMessage.info.bounced : undefined,
6071
inMessageBounceable: tx.inMessage.info.type === 'internal' ? tx.inMessage.info.bounce : undefined,
@@ -67,6 +78,7 @@ export function flattenTransaction(tx: Transaction): FlatTransaction {
6778
to: undefined,
6879
on: undefined,
6980
value: undefined,
81+
ec: undefined,
7082
body: undefined,
7183
inMessageBounced: undefined,
7284
inMessageBounceable: undefined,
@@ -108,6 +120,15 @@ function compareValue(a: any, b: any) {
108120
return a.equals(b)
109121
}
110122

123+
if (a instanceof Array) {
124+
if (!(b instanceof Array)) return false
125+
if (a.length !== b.length) return false
126+
for (let i = 0; i < a.length; i++) {
127+
if (!compareValue(a[i], b[i])) return false
128+
}
129+
return true
130+
}
131+
111132
return a === b
112133
}
113134

0 commit comments

Comments
 (0)