How can I run a truffle test on an existing contract?

656 views Asked by At

I'm working on a simple ethereum contract and it's truffle test counterpart, but the issue I'm running into is that I need the test to call an old deployment of the contract, instead of redeploying it every time.

In the truffle documentation, it says the contract() function should be used when the contract is to be redeployed and mocha's describe() in all other cases, but even using describe, the geth client reports redeploying the contract evey time.

Here is the test:

var md5 = require('md5');
var AuditRecord = artifacts.require("AuditRecord");

describe('AuditRecord', function() {

    before(function() {

        audit = AuditRecord.at('0x30ad3ceaf3f04696d1f7c8c4fbb9cfe4f7041822');

            for (var i = 0; i < 10; ++i) {
                if (Math.random() < 0.3) {
                    audit.enter(i, i, md5("test"), md5("data"), Date.now().toFixed());
                } else {
                    audit.enter(i, i, md5("special_case"), md5("data"), Date.now().toFixed());
                }
            }

            return audit.LogRecord({}, { fromBlock: 0, toBlock: 'latest'});
        });
    it("should read data", function() {
        auditLog = AuditRecord.at('0x30ad3ceaf3f04696d1f7c8c4fbb9cfe4f7041822').LogRecord({}, { fromBlock: 0, toBlock: 'latest'});


        auditLog.get(function(err, data) {
                console.log("\n\n\n\t.:::: testing lookup:\n")
                if (err) {
                    console.log(err);
                    return false;
                }

                for (obj in data) {
                    console.log("entry: @ " + Date(data[obj].args.timestamp).toString());
                    console.log("\tuser: " + web3.toAscii(data[obj].args.user));
                    console.log("\tpatient: " + web3.toAscii(data[obj].args.patient));
                    console.log("\toperation: " + data[obj].args.operation);
                    //console.log(JSON.stringify(data[obj].args.));
                }

                assert(10 < data.length); 

            });




    })
})

The test works in the sense that it finds my previously deployed contract at the hardcoded address, but for some reason it also deploys both the migrations.sol and auditrecord.sol on unrelated addresses every time. My aim is to refer to the same contract every time this test is ran.

Is there a way to achieve this?

0

There are 0 answers