I am trying to write tests for my contract, which stores an user as follows:

    type userData is record [
    addressSet : set(bytes);
    storedAmount : tez;

My storage is a big_map as follows:

type storage is big_map (string, userData);

When I am trying to run the contract, it compiles, but fails on the compilation with

Error: while migrating Vault: [0] Invalid bytes: 0,116,0,122,0,49,0,104,0,115,0,88,0,112,0,107,0,101,0,118,0,87,0,74,0,87,0,107,0,101,0,57,0,116,0,105,0,107,0,111,0,103,0,74,0,102,0,86,0,50,0,116,0,68,0,56,0,100,0,119,0,120,0,80,0,82,0,101,0,70,0,85,...

This if the initial storage json I am providing for the migration:

initial: {

My migration script for truffle looks like this:

const Vault = artifacts.require("Vault");
const {MichelsonMap} = require("@taquito/taquito");
const acc = require ("../scripts/sandbox/accounts");

function packString(str) {
    var bytes = [];
    for(var i = 0, n = str.length; i < n; i++) {
        var char = str.charCodeAt(i);
        bytes.push(char >>> 8, char & 0xFF);
    return bytes;

module.exports = async (deployer, _network, accounts) => {
    const identifier = acc.initial.identifier;
    const addressSetBytes = [];
    // Access the "initial" json stated above to get the string addresses
    const address1Bytes = packString(acc.initial.addressSet[0]);
    const address2Bytes = packString(acc.initial.addressSet[1]);
        const userData =
            addressSet: addressSetBytes,
            storedAmount: acc.initial.storedAmount,
        const testUser = "Mike";
    const storage = new MichelsonMap();
    storage.set(testUser, userData);
    deployer.deploy(Vault, storage);

Can anybody see what I am doing wrong and why the byte array I am providing should be wrong?


It worked as soon as I provided the HEX of the addressSet[] values. Maybe someone can explain why this is the case. I stumbled upon this solution after trying out for hours by accident.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.