Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix insoncistent signers/proposers test #53

Open
wants to merge 2 commits into
base: master
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
15 changes: 12 additions & 3 deletions tests/Multisig.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,12 @@ describe('Multisig', () => {
const malformed = Dictionary.empty(Dictionary.Keys.Uint(8), Dictionary.Values.Address());
malformed.set(0, randomAddress());
malformed.set(2, randomAddress());

const packDict = (dict: Dictionary<number, Address>) => beginCell().storeDictDirect(dict).endCell();

let updateCell = beginCell().storeUint(Op.actions.update_multisig_params, 32)
.storeUint(4, 8)
.storeDict(malformed) // signers
.storeRef(packDict(malformed)) // signers
.storeDict(null) // empty proposers
.endCell();

Expand Down Expand Up @@ -544,10 +547,16 @@ describe('Multisig', () => {
malformed.set(1, randomAddress());
malformed.set(2, randomAddress());

const origSigners = Dictionary.empty(Dictionary.Keys.Uint(8), Dictionary.Values.Address());

for(let i = 0; i < signers.length; i++) {
origSigners.set(i, signers[i]);
}

updateCell = beginCell().storeUint(Op.actions.update_multisig_params, 32)
.storeUint(4, 8)
.storeDict(null) // Empty signers? Yes, that is allowed
.storeDict(malformed) // proposers
.storeRef(packDict(origSigners)) // Original signers
.storeDict(malformed) // malformed proposers
.endCell();

// All over again
Expand Down
32 changes: 28 additions & 4 deletions wrappers/Multisig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, beginCell, Cell, Dictionary, MessageRelaxed, storeMessageRelaxed, Contract, contractAddress, ContractProvider, Sender, SendMode, internal, toNano } from '@ton/core';
import { Address, beginCell, Cell, Dictionary, MessageRelaxed, storeMessageRelaxed, Contract, contractAddress, ContractProvider, Sender, SendMode, internal, toNano, DictionaryValue } from '@ton/core';
import { Op, Params } from "./Constants";

export type Module = {
Expand All @@ -23,6 +23,18 @@ export type UpdateRequest = {
export type Action = TransferRequest | UpdateRequest;
export type Order = Array<Action>;

const AddressValueStrict: DictionaryValue<Address> = {
serialize: (address, builder) => {
builder.storeAddress(address);
},
parse: (src) => {
const address = src.loadAddress();
if(src.remainingBits > 0 || src.remainingRefs > 0) {
throw new Error(`Value supposed to contain address only, but extra ${src.remainingBits} bits and ${src.remainingRefs} present!`);
}
return address;
}
}
function arrayToCell(arr: Array<Address>): Dictionary<number, Address> {
let dict = Dictionary.empty(Dictionary.Keys.Uint(8), Dictionary.Values.Address());
for (let i = 0; i < arr.length; i++) {
Expand All @@ -42,7 +54,7 @@ function moduleArrayToCell(arr: Array<Module>) {
function cellToArray(addrDict: Cell | null) : Array<Address> {
let resArr: Array<Address> = [];
if(addrDict !== null) {
const dict = Dictionary.loadDirect(Dictionary.Keys.Uint(8), Dictionary.Values.Address(), addrDict);
const dict = Dictionary.loadDirect(Dictionary.Keys.Uint(8), AddressValueStrict, addrDict);
resArr = dict.values();
}
return resArr;
Expand Down Expand Up @@ -259,11 +271,23 @@ export class Multisig implements Contract {
}

async getMultisigData(provider: ContractProvider) {
let signers: Address[];
let proposers: Address[];
const { stack } = await provider.get("get_multisig_data", []);
const nextOrderSeqno = stack.readBigNumber();
const threshold = stack.readBigNumber();
const signers = cellToArray(stack.readCellOpt());
const proposers = cellToArray(stack.readCellOpt());
try {
signers = cellToArray(stack.readCellOpt());
}
catch(e) {
throw new Error("Signers dictionary is malformed: " + e);
}
try {
proposers = cellToArray(stack.readCellOpt());
}
catch(e) {
throw new Error("Proposers dictionary is malformed: " + e);
}
return { nextOrderSeqno, threshold, signers, proposers};
}
}