1

My truffle-config.js has

const { alice } = require('./scripts/sandbox/accounts');
module.exports = {
  contracts_directory: "./contracts/main",
  networks: {
    development: {
      host: "http://localhost",
      port: 8732,
      network_id: "*",
      secretKey: alice.sk,
      type: "tezos"
    },

and my test has

const { networks } = require('./../truffle-config');
networks.development.secretKey = charlie.sk;
tx = await contract_instance.register(bob.pkh);

But this function call/transaction is still originating from alice and not from charlie. How do I fix that? I would like to be able to change the caller throughout the unit test if that is possible.

2

I haven't found a solution myself using what is provided by Truffle to do what you want, so here is what I do. I guess you must be using Taquito. In this case, you can use this function to change the signer whenever you need:

const signerFactory = async pk => {
  await Tezos.setProvider({ signer: new InMemorySigner(pk) });
  return Tezos;
};

However, this means that you have to create your own Tezos singleton object and you cannot use Truffle syntax anymore to bypass Truffle default settings, for example:

let contractInstance;

before(async () => {
    Tezos.setProvider({
      rpc: `${truffleConfig.networks.development.host}:${truffleConfig.networks.development.port}`
    });
    await signerFactory(alice.sk);

    const contract = await Contract.deployed();
    /**
     * Display the current contract address for debugging purposes
     */
    console.log("Contract deployed at:", contract.address);

    contractInstance = await Tezos.wallet.at(contract.address);
  });

and calling an entrypoint of the contract would look like what you do in a dapp:

tx = await contractInstance.register(bob.pkh).send();

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.