-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_main.py
69 lines (56 loc) · 2.93 KB
/
test_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import unittest
from unittest.mock import patch
import main
class TestMainFunctions(unittest.TestCase):
# The test_main function is testing the main function from the main module.
# It sets up a mock contract, calls the main function with the mock contract as input,
# and then checks that the output is as expected.
@patch('main.Web3')
def test_main(self, mock_web3):
# Set up test data
mock_web3.eth.contract.return_value = 'test_contract'
# Call the function with test inputs
result = main.main('test_contract')
# Compare actual output with expected output using assertEqual
self.assertEqual(result, 'expected_result')
# The test_total_supply function is testing the total_supply function from the main module.
# It sets up a mock contract, calls the total_supply function with the mock contract as input,
# and then checks that the output is as expected.
@patch('main.Web3')
def test_total_supply(self, mock_web3):
# Set up test data
mock_web3.eth.contract.return_value = 'test_contract'
# Call the function with test inputs
result = main.total_supply('test_contract')
# Compare actual output with expected output using assertEqual
self.assertEqual(result, 'expected_result')
# The test_write_to_csv function is testing the write_to_csv function from the main module.
# It sets up some test token owners and a test file name, calls the write_to_csv function
# with the test token owners and file name as input, and then checks that the file was written correctly.
@patch('main.Web3')
def test_write_to_csv(self, mock_web3):
# Set up test data
token_owners = {'1': 'wallet1', '2': 'wallet2'}
file_name = 'test.csv'
# Call the function with test inputs
main.write_to_csv(token_owners, file_name)
# Check if the file was written correctly
with open(file_name, 'r') as f:
content = f.read()
self.assertEqual(content, 'expected_content')
# The test_create_clean_snapshot function is testing the create_clean_snapshot function from the main module.
# It sets up a test input file and output file, calls the create_clean_snapshot function
# with the test input file and output file as input, and then checks that the output file was written correctly.
@patch('main.Web3')
def test_create_clean_snapshot(self, mock_web3):
# Set up test data
input_file = 'test_input.csv'
output_file = 'test_output.csv'
# Call the function with test inputs
main.create_clean_snapshot(input_file, output_file)
# Check if the file was written correctly
with open(output_file, 'r') as f:
content = f.read()
self.assertEqual(content, 'expected_content')
if __name__ == '__main__':
unittest.main()