Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
truffle & soliditycant access to a function in test

after i run commande truffle test i got this error

TypeError: _character.getName is not a function

my test file

let Game = artifacts.require("./Game.sol");
let Character = artifacts.require("./Character.sol");

const PROVIDED_NAME = "TEST";

contract("Game", (accounts) => {

    let creatorAccount = accounts[0];

    it("should create a character with the name provided", () => {
        let _game;
        let _character;

        return Game.deployed()
            .then(instance => {
                _game = instance;
                return _game.createCharacter(PROVIDED_NAME, { from: creatorAccount });
            })
            .then(result => {
                return _game.getCharacter();
            })
            .then(character => {
                _character = Character.at(character);
                return _character.getName();
            })
            .then(name => {
                assert.equal(name, PROVIDED_NAME, "Failed to create a character with the provided name");
            });
    });
});

and this my Character.sol file

// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

contract Character {
    string private _name;

    constructor(string memory name) public {
        _name = name;
    }

    function getName() public view returns (string memory) {
        return _name;
    }
}

im using

Truffle v5.5.20 (core: 5.5.20) Ganache v7.2.0 Solidity - 0.8.15 (solc-js) Node v16.15.1 Web3.js v1.7.4

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think the issue is with the way how you require them. you should not pass the directory path, instead pass the name of the contracts, truffle will assign them.

let Game = artifacts.require("NameOfGamecontract");
let Character = artifacts.require("NameOfCharacterContract");
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda