3

With the below i'm deploying and then setting some test records. However when I test it doesn't seem to see these records. TESTING OUTPUT
ignore # variation as i hadn't updated it in the test, it still returns 0 when it should return 4 now (i believe).

Repository link in case you want to see something else

Test function:

/**
* @dev Checks Valid CredentialOrg Credential Count, checks if inital conditions are correct from migration.
*/
function testSelectValidOrgCredentialCount() public {

    address contractOwner = credentialFactory.getOwner();
    uint256 testVal = uint256(credentialFactory.selectOrgCredentialCount(contractOwner));
    uint256 expected = 4;
    Assert.equal(testVal, expected, "Expected Credential Count (4)");
}

create function call:

/**
* @dev allows credentialing Orgs to create new credentials
* @param _credentialLevel Credential Level
* @param _credentialTitle CredentialTitle
* @param _credentialDivision Credential Division
* @return insertStatus - true false if insert happened.
*/
function createCredential(string _credentialLevel, string _credentialTitle, string _credentialDivision, address _credentialOrgAddress) 
public onlyOwner
returns (bool insertStatus)
{
    emit CredentialFactoryActivity(msg.sender, _credentialTitle, "New Credential Add (ATTEMPT)");
    insertStatus = false;
    require(bytes(_credentialLevel).length > 0 && bytes(_credentialLevel).length < 50, "createCredential - Level length problem");
    require(bytes(_credentialTitle).length > 0 && bytes(_credentialTitle).length < 70, "createCredential - Title length problem");
    require(bytes(_credentialDivision).length >= 0 && bytes(_credentialDivision).length < 50, "createCredential - Division length problem");
    uint32 position = uint32(orgAddressToCredentials[_credentialOrgAddress].push(Credential(_credentialOrgAddress, _credentialLevel, _credentialTitle, _credentialDivision, uint32(block.timestamp))));
    if(position > 0){
        insertStatus = true;
        orgAddressToCredentialTotalCount[_credentialOrgAddress] = orgAddressToCredentialTotalCount[_credentialOrgAddress].add(1);
        emit CredentialFactoryActivity(_credentialOrgAddress, _credentialTitle, "New Credential Add (SUCCCESS)");
    } else {
        emit CredentialFactoryActivity(_credentialOrgAddress, _credentialTitle, "New Credential Add (FAILED)");
    }
}

it should be a simple retrieval call,

/**
* @dev allows checking of CredentialCount of a CredentialOrg
* @param _credentialOrgAddress Address of Credential Org
* @return returnCredentialCount - returns count of credentials of org.
*/
function selectOrgCredentialCount(address _credentialOrgAddress)
public view 
returns (uint32 returnCredentialCount)
{
    returnCredentialCount = orgAddressToCredentialTotalCount[_credentialOrgAddress];
    return (returnCredentialCount);
}

and here is the deploy scripting:

var SafeMath32 = artifacts.require("./SafeMath32.sol");
var CredentialOrgFactory = artifacts.require("CredentialOrgFactory");  
var CredentialFactory = artifacts.require("CredentialFactory");        
var ApplicantFactory = artifacts.require("ApplicantFactory");          
var ProcessApplicants = artifacts.require("ProcessApplicants");

module.exports = async function(deployer, accounts) {
  let safeMathInst, aInst, bInst, cInst, dInst;

  await Promise.all([
    deployer.deploy(SafeMath32),
    deployer.deploy(CredentialOrgFactory),
    deployer.deploy(CredentialFactory),
    deployer.deploy(ApplicantFactory),
    deployer.deploy(ProcessApplicants),
    deployer.link(SafeMath32,[CredentialOrgFactory,CredentialFactory,ApplicantFactory])
]);

instances = await Promise.all([
SafeMath32.deployed(),
CredentialOrgFactory.deployed(),
CredentialFactory.deployed(),
ApplicantFactory.deployed(),
ProcessApplicants.deployed(),
])

aInst = instances[1];
bInst = instances[2];
cInst = instances[3];
dInst = instances[4];

results = await Promise.all([
// Generate a base record
console.log("StartRec Creation"),
console.log("CredentialOrg Recs, owner, address of CredentialFactory, ApplicantFactory, and ProcessApplicants"),
aInst.createCredentialOrg("INITRECORD", "BASE INIT RECORD", 0x5a186B7FeC36909678211F69beB67EC3b1E4fFBB),
// Grant access to all contracts (for isCredentialOrg)  
// this doesn't quite acomplish what i'm trying to get done... as modifer onlyBy(msg.sender) still fails..
aInst.createCredentialOrg("CREDENTIAL", "CREDENTIALFACTORY", bInst.address),
aInst.createCredentialOrg("APPLICANT", "APPLICANTFACTORY", cInst.address),
aInst.createCredentialOrg("PROCESS", "PROCESSAPPLICANTS", dInst.address),

// Set Address of bInst so it can point at aInst
console.log("setAddress CredentialFactory: for CredentialOrgFactory"),
bInst.setAddress(aInst.address),
console.log("create a base set of credentials for testing"),
bInst.createCredential("Credential1", "AAAA", "AAAAAA", 0x5a186B7FeC36909678211F69beB67EC3b1E4fFBB),
bInst.createCredential("Credential2", "BBBB", "BBBBBB", 0x5a186B7FeC36909678211F69beB67EC3b1E4fFBB),
bInst.createCredential("Credential3", "CCCC", "CCCCCC", 0x5a186B7FeC36909678211F69beB67EC3b1E4fFBB),
bInst.createCredential("Credential4", "DDDD", "DDDDDD", 0x5a186B7FeC36909678211F69beB67EC3b1E4fFBB),

// Set Address of cInst so it can point at aInst
console.log("setAddress ApplicantFactory: for CredentialOrgFactory"),
cInst.setAddress(aInst.address),
console.log("insert 5 Applicant Records, for testing."),
cInst.createApplicant(0x5a186B7FeC36909678211F69beB67EC3b1E4fFBB, "123456781", "987654321", "TESTAPPLICANT1", "TESTAPPLICANT1"),
cInst.createApplicant(0x5a186B7FeC36909678211F69beB67EC3b1E4fFBB, "123456782", "987654322", "TESTAPPLICANT2", "TESTAPPLICANT2"),
cInst.createApplicant(0x5a186B7FeC36909678211F69beB67EC3b1E4fFBB, "123456783", "987654323", "TESTAPPLICANT3", "TESTAPPLICANT3"),
cInst.createApplicant(0x5a186B7FeC36909678211F69beB67EC3b1E4fFBB, "123456784", "987654324", "TESTAPPLICANT4", "TESTAPPLICANT4"),
cInst.createApplicant(0x5a186B7FeC36909678211F69beB67EC3b1E4fFBB, "123456785", "987654325", "TESTAPPLICANT5", "TESTAPPLICANT5"),

// Set Address of dInst so it can point at aInst, bInst, and cInst
dInst.setAddress(aInst.address, bInst.address, cInst.address)
]);

};
1

You're missing quotes around addresses in your JavaScript. E.g. this line:

bInst.createCredential("Credential1", "AAAA", "AAAAAA", 0x5a186B7FeC36909678211F69beB67EC3b1E4fFBB),

needs to be this:

bInst.createCredential("Credential1", "AAAA", "AAAAAA", "0x5a186B7FeC36909678211F69beB67EC3b1E4fFBB"),

(This is true throughout your deployment script.)

  • thanks! that explains some varying results, moving forward again! – shaddow Aug 19 '18 at 21:18

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.