def main(): # Creating and loading tests ad = Address.create(PW, LABEL) ad_b = Address.load(PW, LABEL) print(ad.public_key == ad_b.public_key) print(ad.raw == ad_b.raw) # Wallet tests wallet = Wallet() wallet.sign_up(PW2, LABEL2) print(wallet.current_address.label) wallet2 = Wallet() wallet2.log_in(PW2, LABEL2) print(wallet2.current_address.label) # Transaction test transaction = wallet.create_transaction(ad.raw, 20) print( '\tReceiver: {0}\n\tAmount: {1}\n\tSignature: {2}\n\t Timestamp: {3}'. format(transaction.receiver, transaction.amount, transaction.signature, transaction.timestamp)) # Signature verification example (and therefore test) verify_signature(transaction) transaction2 = Transaction.parse(Transaction.serialize(transaction)) transaction.sender_public_key = ad.public_key # Changing the public key so signature shouldn't be correct verify_signature(transaction) print("TX2 verify", transaction2.verify_signature())
def AddAddress(diachi): """ tạo một địa chỉ mới Thêm địa chỉ mới vào trong database trả về địa chỉ được tạo """ address = Address(address_line=diachi) address.save() return address
def test2(self): address1 = Address(address="인천광역시 중구 운서동 2886-13") tax_office = address1.tax_office assert tax_office.code == 121 assert tax_office.account_number == 110259 assert address1.road_name == "운서2로"
def verify_transactions(self, block): """ Return a list of invalid transactions """ bad_transactions = [] senders_balance = dict() for transaction in block.transactions: if transaction.verify_signature(): sender_address = Address.generate_address( transaction.sender_public_key) if sender_address not in senders_balance: senders_balance[ sender_address] = self.blockchain.get_balance( sender_address) if senders_balance[sender_address] >= transaction.amount: senders_balance[sender_address] -= transaction.amount if transaction.receiver not in senders_balance: senders_balance[ transaction. receiver] = self.blockchain.get_balance( transaction.receiver) senders_balance[ transaction.receiver] += transaction.amount else: bad_transactions.append(transaction) else: bad_transactions.append(transaction) return bad_transactions
def mutate(self, info, user_data): user = get_user_model()(username=user_data.username, email=user_data.email, first_name=user_data.first_name, last_name=user_data.last_name) user.set_password(user_data.password) user.save() customer = Customer(user=user, phone=user_data.phone) customer.save() address = Address(customer=customer, street=user_data.street, city=user_data.city, country=user_data.country, zip_code=user_data.zip_code) address.save() return CreateUser(user=customer)
def update(self, instance, validated_data): address_data = validated_data.pop('address') id = instance.address.id instance = Hoarding(**validated_data) instance.address = Address(**address_data) instance.address.id = id instance.address.save() # instance.save(ddress=instance.address) return instance
def test(self): address1 = Address(address="서울특별시 서초구 반포대로 22길 100") tax_office = address1.tax_office assert tax_office.code == 214 assert tax_office.account_number == 180658 assert address1.road_name == "반포대로22길" assert address1.zip_code == "06650" assert LocalTaxGovernment.get_by_human_address(address1.지번_address) == LocalTaxGovernment.objects.get( uname="서초구청" )
def test(self): address = Address.objects.get(address="경기도 가평군") local_tax_government = LocalTaxGovernment.objects.get( local_tax_government_name="가평군청") assert address.local_tax_government.uname == "가평군청" assert address.local_tax_government == local_tax_government local_tax_government2 = LocalTaxGovernment.objects.get( local_tax_government_name="오정구청") human_address1 = Address( address="경기도 부천시 오정구 여월동 316 여월휴먼시아5단지아파트").지번_address assert LocalTaxGovernment.get_by_human_address( human_address=human_address1) == local_tax_government2 human_address2 = Address( address="서울특별시 서초구 반포대로22길 100 삼덕빌딩").지번_address local_tax_government3 = LocalTaxGovernment.get_by_human_address( human_address=human_address2) assert local_tax_government3.local_tax_government_name == "서초구청" human_address3 = Address(address="서울특별시 강남구 테헤란로 142").지번_address local_tax_government4 = LocalTaxGovernment.get_by_human_address( human_address=human_address3) assert local_tax_government4 is None human_address4 = Address(address="서울특별시 강남구 강남대로 382 메리츠타워").지번_address local_tax_government5 = LocalTaxGovernment.get_by_human_address( human_address=human_address4) assert local_tax_government5 is None local_tax_government6 = LocalTaxGovernment.objects.get( local_tax_government_name="오정구청") human_address5 = Address( address="경기도 부천시 여월동 316 여월휴먼시아5단지아파트").지번_address assert LocalTaxGovernment.get_by_human_address( human_address=human_address5) == local_tax_government6
def test(self): addr1 = "운서" address1 = Address() address1.address = addr1 road_name = address1.road_name assert road_name is None address2 = Address(address="인천광역시 중구 운서동 2886-13 노벨빌라돔") assert address2.road_name == "운서2로" address3 = Address(address="인천광역시 중구 운서2로 31") assert address3.road_name == "운서2로" address4 = Address(address="인천광역시 중구 운서동 2886-13") assert address4.road_name == "운서2로" address5 = Address(address="경기도 부천시 원미구 원미1동 두산아파트 101동 1205호") assert address5.road_name == "원미로144번길" address6 = Address(address="경기도 화성시 영통로50번길 27, 106동 103호") assert address6.road_name == "영통로50번길"
def test_get_tax_office_name(self): address1 = Address(address="인천광역시 중구 운서동 2886-13") tax_office = address1.tax_office assert tax_office.uname == "인천세무서" address2 = Address(address="인천광역시 중구 운서2로 31") tax_office2 = address2.tax_office assert tax_office2.uname == "인천세무서" address3 = Address(address="서울특별시 서초구 반포대로 22길 100") tax_office3 = address3.tax_office assert tax_office3.uname == "서초세무서" address4 = Address(address="경기도 화성시 영통로50번길 3") tax_office4 = address4.tax_office assert tax_office4.uname == "동수원세무서" address5 = Address(address="경기도 부천시 오정구 여월동 316") tax_office5 = address5.tax_office assert tax_office5.uname == "부천세무서" address6 = Address(address="경기도 부천시 원미로 144번길 45") tax_office6 = address6.tax_office assert tax_office6.uname == "부천세무서"
def sign_up(self, password, address_label=''): self.current_address = Address.create(password, address_label)
def log_in(self, password, label, dir=None): if dir == None: self.current_address = Address.load(password, label) else: self.current_address = Address.load(password, label, dir) return self.current_address != None