diff --git a/blockchain.json b/blockchain.json index 64d7ef3..5b20fb8 100644 --- a/blockchain.json +++ b/blockchain.json @@ -1,6 +1,6 @@ [ { - "hash": "0", - "previousHash": null + "previousHash": null, + "hash": "0" } ] \ No newline at end of file diff --git a/jest-html-reporters-attach/index/result.js b/jest-html-reporters-attach/index/result.js index dafe634..9658bcf 100644 --- a/jest-html-reporters-attach/index/result.js +++ b/jest-html-reporters-attach/index/result.js @@ -1 +1 @@ -window.jest_html_reporters_callback__({"numFailedTestSuites":3,"numFailedTests":3,"numPassedTestSuites":0,"numPassedTests":0,"numPendingTestSuites":0,"numPendingTests":0,"numRuntimeErrorTestSuites":0,"numTodoTests":0,"numTotalTestSuites":3,"numTotalTests":3,"startTime":1685453786212,"success":false,"testResults":[{"numFailingTests":1,"numPassingTests":0,"numPendingTests":0,"numTodoTests":0,"perfStats":{"end":1685453786803,"runtime":422,"slow":false,"start":1685453786381},"testFilePath":"/home/eshaan/Desktop/week-0-web3/tests/init-blockchain.test.js","failureMessage":"\u001b[1m\u001b[31m \u001b[1m● \u001b[22m\u001b[1mcorrectly initialised a blockchain\u001b[39m\u001b[22m\n\n ReferenceError: blockchain is not defined\n\u001b[2m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m 8 |\u001b[39m \t\u001b[90m// Create a blockchain constant containing genesisBlock\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m 9 |\u001b[39m \t\u001b[90m// Refer writeBlockchain function from blockchain-helpers\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m\u001b[31m\u001b[1m>\u001b[22m\u001b[2m\u001b[39m\u001b[90m 10 |\u001b[39m \twriteBlockchain(blockchain)\u001b[33m;\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m |\u001b[39m \t \u001b[31m\u001b[1m^\u001b[22m\u001b[2m\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m 11 |\u001b[39m }\u001b[33m;\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m 12 |\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m 13 |\u001b[39m module\u001b[33m.\u001b[39mexports \u001b[33m=\u001b[39m { initBlockchain }\u001b[33m;\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m\u001b[22m\n\u001b[2m \u001b[2mat blockchain (\u001b[22m\u001b[2msrc/init-blockchain.js\u001b[2m:10:18)\u001b[22m\u001b[2m\u001b[22m\n\u001b[2m \u001b[2mat Object.initBlockchain (\u001b[22m\u001b[2m\u001b[0m\u001b[36mtests/init-blockchain.test.js\u001b[39m\u001b[0m\u001b[2m:5:2)\u001b[22m\u001b[2m\u001b[22m\n","testResults":[{"ancestorTitles":[],"duration":1,"failureMessages":["ReferenceError: blockchain is not defined\n at blockchain (/home/eshaan/Desktop/week-0-web3/src/init-blockchain.js:10:18)\n at Object.initBlockchain (/home/eshaan/Desktop/week-0-web3/tests/init-blockchain.test.js:5:2)\n at Promise.then.completed (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/utils.js:293:28)\n at new Promise ()\n at callAsyncCircusFn (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/utils.js:226:10)\n at _callCircusTest (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/run.js:297:40)\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\n at _runTest (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/run.js:233:3)\n at _runTestsForDescribeBlock (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/run.js:135:9)\n at run (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/run.js:68:3)\n at runAndTransformResultsToJestFormat (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)\n at jestAdapter (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)\n at runTestInternal (/home/eshaan/Desktop/week-0-web3/node_modules/jest-runner/build/runTest.js:367:16)\n at runTest (/home/eshaan/Desktop/week-0-web3/node_modules/jest-runner/build/runTest.js:444:34)\n at Object.worker (/home/eshaan/Desktop/week-0-web3/node_modules/jest-runner/build/testWorker.js:106:12)"],"fullName":"correctly initialised a blockchain","status":"failed","title":"correctly initialised a blockchain"}]},{"numFailingTests":1,"numPassingTests":0,"numPendingTests":0,"numTodoTests":0,"perfStats":{"end":1685453786807,"runtime":428,"slow":false,"start":1685453786379},"testFilePath":"/home/eshaan/Desktop/week-0-web3/tests/add-block.test.js","failureMessage":"\u001b[1m\u001b[31m \u001b[1m● \u001b[22m\u001b[1msuccessfuly added a block\u001b[39m\u001b[22m\n\n TypeError: Cannot read properties of undefined (reading 'hash')\n\u001b[2m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m 9 |\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m 10 |\u001b[39m \texpect(addedBlock\u001b[33m.\u001b[39mhash)\u001b[33m.\u001b[39mnot\u001b[33m.\u001b[39mtoBe()\u001b[33m;\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m\u001b[31m\u001b[1m>\u001b[22m\u001b[2m\u001b[39m\u001b[90m 11 |\u001b[39m \texpect(addedBlock\u001b[33m.\u001b[39mpreviousHash)\u001b[33m.\u001b[39mtoBe(previousBlock\u001b[33m.\u001b[39mhash)\u001b[33m;\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m |\u001b[39m \t \u001b[31m\u001b[1m^\u001b[22m\u001b[2m\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m 12 |\u001b[39m \texpect(addedBlock\u001b[33m.\u001b[39mtransactions)\u001b[33m.\u001b[39mtoMatchObject([\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m 13 |\u001b[39m \t\t{\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m 14 |\u001b[39m \t\t\tfromAddress\u001b[33m:\u001b[39m \u001b[32m\"123\"\u001b[39m\u001b[33m,\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m\u001b[22m\n\u001b[2m \u001b[2mat Object.hash (\u001b[22m\u001b[2m\u001b[0m\u001b[36mtests/add-block.test.js\u001b[39m\u001b[0m\u001b[2m:11:53)\u001b[22m\u001b[2m\u001b[22m\n","testResults":[{"ancestorTitles":[],"duration":2,"failureMessages":["TypeError: Cannot read properties of undefined (reading 'hash')\n at Object.hash (/home/eshaan/Desktop/week-0-web3/tests/add-block.test.js:11:53)\n at Promise.then.completed (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/utils.js:293:28)\n at new Promise ()\n at callAsyncCircusFn (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/utils.js:226:10)\n at _callCircusTest (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/run.js:297:40)\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\n at _runTest (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/run.js:233:3)\n at _runTestsForDescribeBlock (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/run.js:135:9)\n at run (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/run.js:68:3)\n at runAndTransformResultsToJestFormat (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)\n at jestAdapter (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)\n at runTestInternal (/home/eshaan/Desktop/week-0-web3/node_modules/jest-runner/build/runTest.js:367:16)\n at runTest (/home/eshaan/Desktop/week-0-web3/node_modules/jest-runner/build/runTest.js:444:34)\n at Object.worker (/home/eshaan/Desktop/week-0-web3/node_modules/jest-runner/build/testWorker.js:106:12)"],"fullName":"successfuly added a block","status":"failed","title":"successfuly added a block"}]},{"numFailingTests":1,"numPassingTests":0,"numPendingTests":0,"numTodoTests":0,"perfStats":{"end":1685453786811,"runtime":431,"slow":false,"start":1685453786380},"testFilePath":"/home/eshaan/Desktop/week-0-web3/tests/add-transaction.test.js","failureMessage":"\u001b[1m\u001b[31m \u001b[1m● \u001b[22m\u001b[1mtesting add-transaction\u001b[39m\u001b[22m\n\n \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoMatchObject\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m)\u001b[22m\n\n \u001b[1mMatcher error\u001b[22m: \u001b[31mreceived\u001b[39m value must be a non-null object\n\n Received has value: \u001b[31mundefined\u001b[39m\n\u001b[2m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m 8 |\u001b[39m \t\u001b[36mconst\u001b[39m addedTransaction \u001b[33m=\u001b[39m transactions[transactions\u001b[33m.\u001b[39mlength \u001b[33m-\u001b[39m \u001b[35m1\u001b[39m]\u001b[33m;\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m 9 |\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m\u001b[31m\u001b[1m>\u001b[22m\u001b[2m\u001b[39m\u001b[90m 10 |\u001b[39m \texpect(addedTransaction)\u001b[33m.\u001b[39mtoMatchObject({\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m |\u001b[39m \t \u001b[31m\u001b[1m^\u001b[22m\u001b[2m\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m 11 |\u001b[39m \t\tfromAddress\u001b[33m:\u001b[39m \u001b[32m\"123\"\u001b[39m\u001b[33m,\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m 12 |\u001b[39m \t\ttoAddress\u001b[33m:\u001b[39m \u001b[32m\"456\"\u001b[39m\u001b[33m,\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m \u001b[0m \u001b[90m 13 |\u001b[39m \t\tamount\u001b[33m:\u001b[39m \u001b[35m789\u001b[39m\u001b[33m,\u001b[39m\u001b[0m\u001b[22m\n\u001b[2m\u001b[22m\n\u001b[2m \u001b[2mat Object.toMatchObject (\u001b[22m\u001b[2m\u001b[0m\u001b[36mtests/add-transaction.test.js\u001b[39m\u001b[0m\u001b[2m:10:27)\u001b[22m\u001b[2m\u001b[22m\n","testResults":[{"ancestorTitles":[],"duration":4,"failureMessages":["Error: \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoMatchObject\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m)\u001b[22m\n\n\u001b[1mMatcher error\u001b[22m: \u001b[31mreceived\u001b[39m value must be a non-null object\n\nReceived has value: \u001b[31mundefined\u001b[39m\n at Object.toMatchObject (/home/eshaan/Desktop/week-0-web3/tests/add-transaction.test.js:10:27)\n at Promise.then.completed (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/utils.js:293:28)\n at new Promise ()\n at callAsyncCircusFn (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/utils.js:226:10)\n at _callCircusTest (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/run.js:297:40)\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\n at _runTest (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/run.js:233:3)\n at _runTestsForDescribeBlock (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/run.js:135:9)\n at run (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/run.js:68:3)\n at runAndTransformResultsToJestFormat (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)\n at jestAdapter (/home/eshaan/Desktop/week-0-web3/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)\n at runTestInternal (/home/eshaan/Desktop/week-0-web3/node_modules/jest-runner/build/runTest.js:367:16)\n at runTest (/home/eshaan/Desktop/week-0-web3/node_modules/jest-runner/build/runTest.js:444:34)\n at Object.worker (/home/eshaan/Desktop/week-0-web3/node_modules/jest-runner/build/testWorker.js:106:12)"],"fullName":"testing add-transaction","status":"failed","title":"testing add-transaction"}]}],"config":{"bail":0,"changedFilesWithAncestor":false,"ci":false,"collectCoverage":false,"collectCoverageFrom":[],"coverageDirectory":"/home/eshaan/Desktop/week-0-web3/coverage","coverageProvider":"babel","coverageReporters":["json","text","lcov","clover"],"detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"expand":false,"findRelatedTests":false,"forceExit":false,"json":false,"lastCommit":false,"listTests":false,"logHeapUsage":false,"maxConcurrency":5,"maxWorkers":7,"noStackTrace":false,"nonFlagArgs":[],"notify":false,"notifyMode":"failure-change","onlyChanged":false,"onlyFailures":false,"openHandlesTimeout":1000,"passWithNoTests":false,"projects":[],"reporters":[["default",{}],["/home/eshaan/Desktop/week-0-web3/node_modules/jest-html-reporters/index.js",{"filename":"index.html","pageTitle":"Web 3 - Week 0","openReport":true,"hideIcon":true}]],"rootDir":"/home/eshaan/Desktop/week-0-web3","runTestsByPath":false,"seed":-1168676141,"skipFilter":false,"snapshotFormat":{"escapeString":false,"printBasicPrototype":false},"testFailureExitCode":1,"testPathPattern":"","testSequencer":"/home/eshaan/Desktop/week-0-web3/node_modules/@jest/test-sequencer/build/index.js","updateSnapshot":"new","useStderr":false,"watch":false,"watchAll":false,"watchman":true,"workerThreads":false},"endTime":1685453786832,"_reporterOptions":{"publicPath":"/home/eshaan/Desktop/week-0-web3","filename":"index.html","expand":false,"pageTitle":"Web 3 - Week 0","hideIcon":true,"testCommand":"","openReport":true,"failureMessageOnly":0,"enableMergeData":false,"dataMergeLevel":1,"inlineSource":false,"urlForTestFiles":"","darkTheme":false,"includeConsoleLog":false},"logInfoMapping":{},"attachInfos":{}}) \ No newline at end of file +window.jest_html_reporters_callback__({"numFailedTestSuites":0,"numFailedTests":0,"numPassedTestSuites":3,"numPassedTests":3,"numPendingTestSuites":0,"numPendingTests":0,"numRuntimeErrorTestSuites":0,"numTodoTests":0,"numTotalTestSuites":3,"numTotalTests":3,"startTime":1686147593425,"success":false,"testResults":[{"numFailingTests":0,"numPassingTests":1,"numPendingTests":0,"numTodoTests":0,"perfStats":{"end":1686147593539,"runtime":95,"slow":false,"start":1686147593444},"testFilePath":"/Users/shashankmittal/Documents/week-0-web3/tests/add-block.test.js","failureMessage":null,"testResults":[{"ancestorTitles":[],"duration":1,"failureMessages":[],"fullName":"successfuly added a block","status":"passed","title":"successfuly added a block"}]},{"numFailingTests":0,"numPassingTests":1,"numPendingTests":0,"numTodoTests":0,"perfStats":{"end":1686147593575,"runtime":34,"slow":false,"start":1686147593541},"testFilePath":"/Users/shashankmittal/Documents/week-0-web3/tests/init-blockchain.test.js","failureMessage":null,"testResults":[{"ancestorTitles":[],"duration":1,"failureMessages":[],"fullName":"correctly initialised a blockchain","status":"passed","title":"correctly initialised a blockchain"}]},{"numFailingTests":0,"numPassingTests":1,"numPendingTests":0,"numTodoTests":0,"perfStats":{"end":1686147593613,"runtime":34,"slow":false,"start":1686147593579},"testFilePath":"/Users/shashankmittal/Documents/week-0-web3/tests/add-transaction.test.js","failureMessage":null,"testResults":[{"ancestorTitles":[],"duration":2,"failureMessages":[],"fullName":"testing add-transaction","status":"passed","title":"testing add-transaction"}]}],"config":{"bail":0,"changedFilesWithAncestor":false,"ci":false,"collectCoverage":false,"collectCoverageFrom":[],"coverageDirectory":"/Users/shashankmittal/Documents/week-0-web3/coverage","coverageProvider":"babel","coverageReporters":["json","text","lcov","clover"],"detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"expand":false,"findRelatedTests":false,"forceExit":false,"json":false,"lastCommit":false,"listTests":false,"logHeapUsage":false,"maxConcurrency":5,"maxWorkers":7,"noStackTrace":false,"nonFlagArgs":[],"notify":false,"notifyMode":"failure-change","onlyChanged":false,"onlyFailures":false,"openHandlesTimeout":1000,"passWithNoTests":false,"projects":[],"reporters":[["default",{}],["/Users/shashankmittal/Documents/week-0-web3/node_modules/jest-html-reporters/index.js",{"filename":"index.html","pageTitle":"Web 3 - Week 0","openReport":true,"hideIcon":true}]],"rootDir":"/Users/shashankmittal/Documents/week-0-web3","runTestsByPath":false,"seed":-296311966,"skipFilter":false,"snapshotFormat":{"escapeString":false,"printBasicPrototype":false},"testFailureExitCode":1,"testPathPattern":"","testSequencer":"/Users/shashankmittal/Documents/week-0-web3/node_modules/@jest/test-sequencer/build/index.js","updateSnapshot":"new","useStderr":false,"watch":false,"watchAll":false,"watchman":true,"workerThreads":false},"endTime":1686147593614,"_reporterOptions":{"publicPath":"/Users/shashankmittal/Documents/week-0-web3","filename":"index.html","expand":false,"pageTitle":"Web 3 - Week 0","hideIcon":true,"testCommand":"","openReport":true,"failureMessageOnly":0,"enableMergeData":false,"dataMergeLevel":1,"inlineSource":false,"urlForTestFiles":"","darkTheme":false,"includeConsoleLog":false},"logInfoMapping":{},"attachInfos":{}}) \ No newline at end of file diff --git a/src/add-block.js b/src/add-block.js index 2f81b5f..1482ec8 100644 --- a/src/add-block.js +++ b/src/add-block.js @@ -11,10 +11,18 @@ const addBlock = () => { const transactions = getTransactions(); // Create a hash, previousHash and transactions property for newBlock and push that into blockchain - - blockchain.push(); + const newBlock={ + previousHash: previousBlock.hash, + hash:previousBlock.hash+20, + transactions:[{ + fromAddress: "123", + toAddress: "456", + amount: 789, + }], + }; + blockchain.push(newBlock); writeBlockchain(blockchain); writeTransactions([]); }; -module.exports = { addBlock }; +module.exports = { addBlock }; \ No newline at end of file diff --git a/src/add-transaction.js b/src/add-transaction.js index 85b7549..c79aa86 100644 --- a/src/add-transaction.js +++ b/src/add-transaction.js @@ -7,10 +7,14 @@ const addTransaction = () => { // Xreate new transactions and push them into transactions.json containing the above properties // Refer blockchain-helpers.js for writeTransactions and getTransactions - + const newTransaction ={ + fromAddress: "123", + toAddress: "456", + amount: 789, + }; const transactions = getTransactions(); - transactions.push(); + transactions.push(newTransaction); writeTransactions(transactions); }; -module.exports = { addTransaction }; +module.exports = { addTransaction }; \ No newline at end of file diff --git a/src/init-blockchain.js b/src/init-blockchain.js index 9e6a994..9a00383 100644 --- a/src/init-blockchain.js +++ b/src/init-blockchain.js @@ -4,6 +4,11 @@ const { writeBlockchain } = require("./blockchain-helpers"); const initBlockchain = () => { // Create a genesisBlock and add appropriate hash and previous hash property to genesisBlock + const genesisBlock={ + previousHash:null, + hash: "0" + }; + const blockchain = [genesisBlock]; // Create a blockchain constant containing genesisBlock // Refer writeBlockchain function from blockchain-helpers diff --git a/transactions.json b/transactions.json index 0637a08..2416fc0 100644 --- a/transactions.json +++ b/transactions.json @@ -1 +1,7 @@ -[] \ No newline at end of file +[ + { + "fromAddress": "123", + "toAddress": "456", + "amount": 789 + } +] \ No newline at end of file