package org.bdware.sc.memory.test;

import java.io.IOException;

public class MemoryDumpTest {
    public static void main(String[] args) throws IOException {
        //memoryRecord("Z_Test_pub2","Z_Test_pub2-1");
        //memoryRecord("Test","Test1");
    }

/*    //仅支持public路径下测试
    public static void memoryRecord(String contractName,String argsFileName) {
        String name = contractName + "/" + contractName;

        //启动合约
        ContractManager cm1 = new ContractManager();
        cm1.yjsPath = JudgeStatus.yjsPath;
        Contract c = new Contract();
        c.setType(ContractType.Sole);
        String id = "169412582";
        c.setID(id);
        c.setScript(RedoRecoverTest.file2Str("/Users/zhangyixuan/Lab/newProject/BDContract/front-agent/BDWareProjectDir/public/" + name + ".yjs"));
        String key  = "{\"publicKey\":\"041d7b4818817736b3d64305675f04e9a00a12ce23c72e6740f83785edcffec6bae2c178fbc934f66d72e26f89a2e7a2c966dc3f0a8e415663c9b933af7a2e9ff8\",\"privateKey\":\"18505919022281880113072981827955639221458448578012075254857346196103069175443\"}";
        SM2KeyPair pair = SM2KeyPair.fromJson(key);
        c.doSignature(pair);
        System.out.println("<<<Start a contract>>> : " + cm1.startContractAndRedirect(c,  null));



        //执行事务
        int count = 0;
        ContractRequest cor = new ContractRequest();
        cor.setContractID(contractName);
        cor.doSignature(pair);
        File file = new File("./cp/recoverTestFiles/affairs/" + contractName + "/" + argsFileName);
        try {
            FileReader fr = new FileReader(file);
            BufferedReader br = new BufferedReader(fr);
            String s = null;
            while((s=br.readLine()) != null) {
                String[] strs = s.split(" ");
                cor.setAction(strs[0]);
                cor.setArg(strs[1]);
                System.out.println("<<<execute the contract>> NO." + (++count) +  "  [Result]" + cm1.execute(cor,null));
            }
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }


        //memoryDump
        long time1 = System.currentTimeMillis();
        File mem = new File("./cp/recoverTestFiles/memory/" + contractName + ".txt");
        String memory = cm1.dumpContract(contractName,mem.getAbsolutePath());
        System.out.println("memory\n" + memory);
        long time2 = System.currentTimeMillis();
        double cost = ((double)time2 - (double)time1)/1000;
        System.out.println("共" + count + "项事务，dump memory 用时" + cost + "s");
    }*/
}

