package org.bdware.sc.test.synctest;

public class RedoRecordTest {

    public static void main(String[] args) {
        transRecord("Z_Test_pub1","Z_Test_pub1-1");
    }

    //仅支持public路径下测试
    public static void transRecord(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/BDWareHttp/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));
//        cm1.engineStartTransRecord(contractName);
//
//
//        //执行事务
//        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));
//            }
//        } catch (IOException e1) {
//            // TODO Auto-generated catch block
//            e1.printStackTrace();
//        }
//
//
//
//
//        //记录最终状态
//        cm1.saveTransRecords(contractName,"./cp/recoverTestFiles/trans/" + contractName);
//        System.out.println("<<<transRecords>>> : \n" + cm1.engineTransRecords2String(contractName));
//
//
//        File mem = new File("./cp/recoverTestFiles/memory/" + contractName + ".txt");
//        String memory1 = cm1.dumpContract(contractName,mem.getAbsolutePath());
//        if(memory1.equals("{\"status\":\"Error\",\"result\":\"Timeout!\"}")) {
//            System.out.println("<<<Memory dump>>> failed");
//            return;
//        }
//        System.out.println("<<<Memory dump>>>" + memory1);
//        System.out.println("共" +count + "项事务记录");
    }

}

